python pandas 如何按日期统计?
发布网友
发布时间:2022-04-30 00:43
我来回答
共1个回答
热心网友
时间:2022-04-18 07:00
你好,你可以参考下面的代码:
import pandas as pd
import datetime,re
df = pd.read_csv("book1.csv")
print(df)
AA = df.sort_values(by=['asktime'])
print (AA)
dataDict ={}
print ("**********")
for index, row in df.iterrows():
print (row)
#print(row['asktime'], row['setment'])
t = re.split("\s+",row['asktime'])[0]
print
if t in dataDict:
if row['sentiment'] in dataDict[t]:
dataDict[t][row['sentiment']] +=1
else:
dataDict[t][row['sentiment']] =1
else:
dataDict[t] = {}
dataDict[t][row['sentiment']] =1
print (dataDict)