为什么Pandas在从字典转换为dataframe时强制将ascii字符串转换为unicode?这是一个特性还是一个已知的bug?
我使用的是Python 2.7.3和Pandas 0.20.2
MWE包含在下面。
import pandas as pd
sample_dict={}
sample_dict['A'] = {'Key_1': 'A1', 'Key-2': 'A2', 'Key_3': 'A3'}
sample_dict['B'] = {'Key_1': 'B1', 'Key-2': 'B2', 'Key_3': 'B3'}
sample_dict['C'] = {'Key_1': 'C1', 'Key-2': 'C2', 'Key_3': 'C3'}
print sample_dict['A'].keys()
sample_df = pd.DataFrame.from_dict(sample_dict, orient='index')
print sample_df.keys()结果如下:
['Key-2', 'Key_1', 'Key_3']
Index([u'Key-2', u'Key_1', u'Key_3'], dtype='object')附录:我遇到了this类似的问题,但它已经停用了几年,并且没有讨论为什么会发生这种情况。
https://stackoverflow.com/questions/44501126
复制相似问题