import pandas as pd
with open('logAq.txt', 'w') as fw:
a=pd.read_csv(r"C:\Users\user\Desktop\dddd.txt", sep=",")
b=a[['dates','user']]
b.groupby(['dates','user'])['dates'].count().sort_index(level=[0,1], ascending=[False,True])
final=b.sort_values(['dates'],ascending=False).groupby(['dates','user'], sort=False)['dates'].count()
fw.write(final)
TypeError:write()参数必须为str,而不是Series
将final
的结果写入txt应该怎么做?
答案 0 :(得分:1)
如果变量final
是列表,那么您只需要遍历值并将值写入输出中即可。
for value in final:
fw.write(value+'\n')
或类似的东西...
答案 1 :(得分:0)
尝试在fw.write(final)之前添加str(final)