寻求帮助,python dataframe统计计数的问题
1个回答
展开全部
没完全理解题主的意思,不知道要的是不是这个:
import pandas as pd
import StringIO
table_buffer = StringIO.StringIO('''shop_id time_stamp_view
1197 2016-10-21
1197 2016-10-22
1198 2016-10-21
1198 2016-10-21
1198 2016-10-23
''')
df = pd.read_table(table_buffer, sep='\s+')
df['count'] = 1
print df.groupby(['shop_id', 'time_stamp_view']).count().reset_index()
# shop_id time_stamp_view count
# 0 1197 2016-10-21 1
# 1 1197 2016-10-22 1
# 2 1198 2016-10-21 2
# 3 1198 2016-10-23 1
import pandas as pd
import StringIO
table_buffer = StringIO.StringIO('''shop_id time_stamp_view
1197 2016-10-21
1197 2016-10-22
1198 2016-10-21
1198 2016-10-21
1198 2016-10-23
''')
df = pd.read_table(table_buffer, sep='\s+')
df['count'] = 1
print df.groupby(['shop_id', 'time_stamp_view']).count().reset_index()
# shop_id time_stamp_view count
# 0 1197 2016-10-21 1
# 1 1197 2016-10-22 1
# 2 1198 2016-10-21 2
# 3 1198 2016-10-23 1
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询