这是df3(pandas dataframe)的样子:
Key Media_type cleaned_text keyword subtopic topic
0 910040 facebook will wait outside post office post office Brand service
1 910040 facebook will wait outside post office will wait random irrelevant
2 218658 facebook there no section post office alabama ups fedex post office Brand service
3 218658 facebook there no section post office alabama ups fedex ups fedex Brand service
4 763587 twitter crazy package delivery rammed car package delivery Shipping company
5 827572 twitter formatting idead delivery done delivery done Shipping country
6 2404106 facebook supoused mexico united states america united states america location marathon
7 1077739 twitter rt ups rt ups retweet service
8 786786 extraterristrial put one toostamp (put[a-za-z]{,5}|made|leave)(.{,8})(stamp) put one's stamp on outlier
9 36283 unkown pute horse stamp (put[a-za-z]{,5}|made|leave)(.{,8})(stamp) put one's stamp on outlier
我想为df3 ['subtopic']中的每个值放置一个过滤器,然后将结果值返回到excel。例如。手动的方法是:
df4 = df3.loc[df3['Subtopic'] == 'Brand']
df4.to_excel('subtopic_FedexDriver.xlsx')
这部分代码的输出如下所示:
Key Media_type cleaned_text keyword subtopic topic
0 910040 facebook will wait outside post office post office Brand service
1 218658 facebook there no section post office alabama ups fedex post office Brand service
2 218658 facebook there no section post office alabama ups fedex ups fedex Brand service
我必须分别为每个子主题执行此操作。有没有办法可以使它自动化?即使将值添加到1个excel文件中的不同excel表中,也可以。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句