gpt4 book ai didi

python-2.7 - 数据帧编码

转载 作者:行者123 更新时间:2023-12-04 13:08:05 26 4
gpt4 key购买 nike

有没有一种方法可以编码我的数据帧的索引?我有一个数据框,其中的索引是国际 session 的名称。
df2= pd.DataFrame(index=df_conf['Conference'], columns=['Citation1991','Citation1992'])
我不断得到:KeyError: 'Leitf\xc3\xa4den der angewandten Informatik'
每当我的代码引用带有未知ascii字母的外国 session 名称时。

我试过了:

df.at[x.encode("utf-8"), 'col1']

df.at[x.encode('ascii', 'ignore'), 'col']

有办法解决吗?我试图查看在创建数据框时是否可以对数据框本身进行编码,但是似乎也无法做到这一点。

最佳答案

如果您不使用csv,并且想对字符串索引进行编码,那么这对我有用:

df.index = df.index.str.encode('utf-8')

关于python-2.7 - 数据帧编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30156012/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com