题解 | #牛客网每日正确与错误的答题次数#
牛客网每日正确与错误的答题次数
https://www.nowcoder.com/practice/bd74b186d5954eb69c00ee804cebe364
import sys for line in sys.stdin: a = line.split() print(int(a[0]) + int(a[1])) import pandas as pd #读取文件 df=pd.read_csv('nowcoder.csv') #把date列转换日期格式,并且在表中添加一列,列名year-month-day df['year-month-day']=pd.to_datetime(df['date']).dt.date #把date列转换日期格式,并赋值给date列(即覆盖) df['date']=pd.to_datetime(df['date'],format='%Y-%m-%d') #把date列设置为索引 df=df.set_index('date') #排序 df=df.sort_values('date') #筛选2021-12 df1=df['2021-12'] #按result,year-month-day这两列分组,统计结果 df2=df1.groupby(['result','year-month-day'])['user_id'].count() print(df2)