How to read UTF-8 files with Pandas?

后端 未结 3 673
傲寒
傲寒 2020-12-14 08:32

I have a UTF-8 file with twitter data and I am trying to read it into a Python data frame but I can only get an \'object\' type instead of unicode strings:

#         


        
3条回答
  •  醉酒成梦
    2020-12-14 08:58

    Pandas stores strings in objects. In python 3, all string are in unicode by default. So if you use python 3, your data is already in unicode (don't be mislead by type object).

    If you have python 2, then use df = pd.read_csv('your_file', encoding = 'utf8'). Then try for example pd.lib.infer_dtype(df.iloc[0,0]) (I guess the first col consists of strings.)

提交回复
热议问题