2017-06-12 10 views
0

辞書からデータフレームへの変換時にパンダが強制的にASCII文字列をユニコードに変換するのはなぜですか?これは機能か既知のバグですか?パンダが文字列の代わりにユニコード列名を強制するのはなぜですか?

私は、Python 2.7.3を使っていますし、パンダ0.20.2

MWEは、以下に含ま。

['Key-2', 'Key_1', 'Key_3'] 
Index([u'Key-2', u'Key_1', u'Key_3'], dtype='object') 

補遺:中

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() 

結果は、私がthis同様の質問に出くわしたが、それは数年のカップルのために活動していますし、なぜこれが起こっている議論しません。

+0

ちょうど興味がありますが、それは主に美学の問題を引き起こしますか? – suvy

+0

主にちょっと迷惑です。 sample_df ['Key_1']として列にアクセスする代わりに、私はsample_df [u'Key_1 ']を使用する必要があります。 – UditG

+0

また、 'Key'とu'Key 'が両方とも辞書に含まれているとどうなるかわかりません。 – UditG

答えて

0

パンダのデータフレームのreprから それは私のpython 3には、任意のUnicodeの接頭辞を見ることはできないはずと確信しています

""" 
    Return a string representation for a particular object. 

    Yields Bytestring in Py2, Unicode String in py3. 
    """ 

言います。

関連する問題