2017-02-14 39 views
0

不知道爲什麼,但是當我加載json文件中的tweets到熊貓時,我得到了很多奇怪的字符。熊貓tweet json奇怪的人物u' '

for file_name in files: 
     if '.json' in file_name: 
      file_path = WORKING_DIR + '/data/' + file_name 

      # Reading the json as a dict 
      with open(file_path) as json_d: 
       data = json.load(json_d, encoding='utf8') 
       json_df = pd.DataFrame.from_dict(data) 
       dfs.append(json_df) 
+0

u' '表示未能使用utf-8編碼解碼字符。如果你應用嚴格的解碼,你會得到錯誤,而不是'''。該文件是否使用其他編碼? – MYGz

回答

1

嘗試使用encoding='utf-16'encoding='utf-8'

在文件file_name中: 如果在file_name中 '上傳.json': FILE_PATH = WORKING_DIR + '/數據/' + FILE_NAME

 # Reading the json as a dict 
     with open(file_path) as json_d: 
      data = json.load(json_d, encoding='utf-16') 
      json_df = pd.DataFrame.from_dict(data) 
      dfs.append(json_df) 

作爲@MYGz建議「u' 」表示未能用'utf-8'解碼字符「」 因此請嘗試使用其他編碼。