2024-09-30 20:19:22 发布
网友
我有一个1100万行的数据框:
我想用'user_id'列和柱状图(y轴:用户数,x轴:tweets数)统计有多少用户发布了相同数量的tweets
'user_id'
我试过这个:
user_tweet_df.groupby('tweet_count').count()
这行不通。有人能帮忙吗?多谢各位
看看下面是否适合你。根据需要使用pandas docs on visualization自定义图形
import matplotlib.pyplot as plt import pandas as pd from tabulate import tabulate tweets_df = pd.DataFrame({'user_id':[312,412,521,577,614,753,965,989], 'user_name':['Mary','Bob','Hans','Nicole','Chris','Matt','Carol','Khan'], 'tweet_count':[207,35,35,1,2,1,1,15]}) print(tabulate(tweets_df, headers='keys'), '\n') grouped_df = tweets_df.groupby('tweet_count').count()[['user_id']] print(tabulate(grouped_df, headers='keys'), '\n') grouped_df.plot(kind='bar') plt.show()
看看下面是否适合你。根据需要使用pandas docs on visualization自定义图形
相关问题 更多 >
编程相关推荐