不确定为什么但是当我将json文件中的推文加载到pandas时,我得到了很多奇怪的字符。
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 :(得分:1)
尝试使用encoding='utf-16'
或encoding='utf-8'
表示文件中的file_name: 如果' .json'在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='utf-16')
json_df = pd.DataFrame.from_dict(data)
dfs.append(json_df)
作为@MYGz建议"你'�'意味着它无法用'utf-8'"来解码角色。 所以尝试使用其他编码。