DA31. 牛客网每日正确与错误的答题次数
描述
现有牛客网12月每天练习题目的数据集nowcoder.csv。包含如下字段(字段之间用逗号分隔):
请你统计2021年12月答题结果正确和错误的前提下每天的答题次数。
以上数据集的输出结果如下:
Python 3 解法, 执行用时: 762ms, 内存消耗: 524288KB, 提交时间: 2022-07-02
import pandas as pd nowcoder = pd.read_csv('nowcoder.csv') nowcoder.rename(columns={'date':'year-month-day'}, inplace=True) df = nowcoder.groupby(['result', 'year-month-day'])['question_id'].count() print(df)
Python 3 解法, 执行用时: 775ms, 内存消耗: 524288KB, 提交时间: 2022-07-02
import pandas as pd from datetime import datetime nowcoder = pd.read_csv('nowcoder.csv') nowcoder.rename(columns={'date':'year-month-day'},inplace=True) print(nowcoder.groupby(by=['result','year-month-day'])['question_id'].count())
Python 3 解法, 执行用时: 781ms, 内存消耗: 524288KB, 提交时间: 2022-07-05
import pandas as pd nowcoder = pd.read_csv('nowcoder.csv') nowcoder.rename(columns={'date':'year-month-day'},inplace=True) df=nowcoder.groupby(['result','year-month-day'])['question_id'].count() print(df)
Python 3 解法, 执行用时: 784ms, 内存消耗: 524288KB, 提交时间: 2022-07-24
import pandas as pd nowcoder = pd.read_csv('nowcoder.csv') nowcoder['year-month-day'] = pd.to_datetime(nowcoder['date']).dt.date time=nowcoder.date.apply(lambda x : x[0:7]) nowcoder=nowcoder[time =='2021/12'] res = nowcoder.groupby(['result','year-month-day'])['year-month-day'].count() print(res)
Python 3 解法, 执行用时: 784ms, 内存消耗: 524288KB, 提交时间: 2022-07-11
import pandas as pd nowcoder = pd.read_csv('nowcoder.csv') nowcoder['year-month-day'] = pd.to_datetime(nowcoder['date']).dt.date print(nowcoder.groupby(['result','year-month-day']).size())