Python 这是否意味着我需要首先标记我的json?

Python 这是否意味着我需要首先标记我的json?,python,Python,我正试图清理一些聊天日志,以便对其进行数据分析,我真的只是掌握了如何做到这一点的字符串。当我试图摆脱stopwords并将文件转换为excel时,我得到了 不可损坏类型:“dict” 这是我的密码 import json import pandas as pd from nltk.corpus import stopwords import re import codecs data = "" stopwords_list = stopwords.words('Taglish') with

我正试图清理一些聊天日志,以便对其进行数据分析,我真的只是掌握了如何做到这一点的字符串。当我试图摆脱stopwords并将文件转换为excel时,我得到了

不可损坏类型:“dict”

这是我的密码

import json
import pandas as pd
from nltk.corpus import stopwords
import re
import codecs

data = ""
stopwords_list = stopwords.words('Taglish')

with codecs.open("1207ChannelMess.json", 'r', 'utf8') as data_file:    
    data = json.load(data_file)

for item in data:
    for key in item:
        if key == "title":
            temp = str(item[key]).lower()
            temp = re.sub('[`~!@#$^&*()\-_=+{};:\'",<.>/?\\|\[\]★]', '', temp)
            temp = ' '.join([word for word in temp.split() if word not in stopwords_list])
            item[key] = temp

with codecs.open('1207ChannelMess.json', 'w', 'utf8') as new_data_file:
    json.dump(data, new_data_file)

df = pd.read_json(codecs.open('1207ChannelMess.json','r','utf-8'))
df.to_excel('out.xlsx',{'remove_timezone': True})
导入json
作为pd进口熊猫
从nltk.corpus导入停止词
进口稀土
导入编解码器
data=“”
stopwords\u list=stopwords.words('Taglish')
使用codecs.open(“1207ChannelMess.json”,“r”,“utf8”)作为数据文件:
data=json.load(数据文件)
对于数据中的项目:
对于输入项:
如果键==“标题”:
temp=str(项[键]).lower()
temp=re.sub('[`~!@$^&*()\-\=+{};:\',/?\\\\\\\[\]★]', '', 温度)
temp=''.join([如果单词不在stopwords\u列表中,则在temp.split()中逐字逐句])
项目[关键]=临时
使用codecs.open('1207ChannelMess.json','w','utf8')作为新的\u数据\u文件:
dump(数据,新的数据文件)
df=pd.read_json(codecs.open('1207ChannelMess.json','r','utf-8'))
to_excel('out.xlsx',{'remove_timezone':True})
这是否意味着json文件需要首先标记化?任何方向都会有帮助

完全回溯

TypeError                                 
Traceback (most recent call last) <ipython-input-46-e84b9b575347> in <module>
     23 
     24 df = pd.read_json(codecs.open('1207ChannelMess.json','r','utf-8'))
---> 25 df.to_excel('out.xlsx',{'remove_timezone': True})
     26 

/opt/anaconda3/lib/python3.7/site-packages/pandas/core/generic.py in to_excel(self, excel_writer, sheet_name, na_rep, float_format, columns, header, index, index_label, startrow, startcol, engine, merge_cells, encoding, inf_rep, verbose, freeze_panes)    
   2254         startcol=startcol,    
   2255             freeze_panes=freeze_panes,
-> 2256             engine=engine,    
   2257         )    
   2258 

/opt/anaconda3/lib/python3.7/site-packages/pandas/io/formats/excel.py in write(self, writer, sheet_name, startrow, startcol, freeze_panes, engine)
    737             startrow=startrow,
    738             startcol=startcol,
--> 739             freeze_panes=freeze_panes,
    740         )
    741         if need_save:

/opt/anaconda3/lib/python3.7/site-packages/pandas/io/excel/_xlsxwriter.py in write_cells(self, cells, sheet_name, startrow, startcol, freeze_panes)
    201         sheet_name = self._get_sheet_name(sheet_name)
    202 
--> 203         if sheet_name in self.sheets:
    204             wks = self.sheets[sheet_name]
    205         else:

TypeError: unhashable type: 'dict'
TypeError
中的回溯(最近一次呼叫)
23
24 df=pd.read_json(codecs.open('1207ChannelMess.json','r','utf-8'))
--->25 df.to_excel('out.xlsx',{'remove_timezone':True})
26
/opt/anaconda3/lib/python3.7/site-packages/pandas/core/generic.py in to_excel(self,excel_writer,sheet_name,na_rep,float_format,columns,header,index,index_label,startrow,startcol,engine,merge_cells,encoding,inf_rep,verbose,freeze_panes)
2254 startcol=startcol,
2255冻结窗格=冻结窗格,
->2256发动机=发动机,
2257         )    
2258
/opt/anaconda3/lib/python3.7/site-packages/pandas/io/formats/excel.py写入(self、writer、sheet\u name、startrow、startcol、freeze\u panes、engine)
737 startrow=startrow,
738 startcol=startcol,
-->739冻结窗格=冻结窗格,
740         )
741如果需要保存:
/opt/anaconda3/lib/python3.7/site-packages/pandas/io/excel//\u xlsxwriter.py输入写入单元格(self、单元格、工作表名称、startrow、startcol、冻结窗格)
201工作表名称=自我。获取工作表名称(工作表名称)
202
-->203如果self.sheets中的工作表名称:
204 wks=自我工作表[工作表名称]
205其他:
TypeError:无法损坏的类型:“dict”

请发布完整的回溯您查看了“到excel”功能吗?请发布完整的回溯您查看了“到excel”功能吗?