Bar graph from dataframe groupby

旧巷老猫 提交于 2019-12-23 08:54:10

问题


import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

df = pd.read_csv("arrests.csv")
df = df.replace(np.nan,0)
df = df.groupby(['home_team'])['arrests'].mean()

I'm trying to create a bar graph for dataframe. Under home_team are a bunch of team names. Under arrests are a number of arrests at each date. I've basically grouped the data by teams with the average arrests for that team. I'm trying to create a bar graph for this but am not sure how to proceed since one column doesn't have a header.

Data


回答1:


copying data from your link and running df = pd.read_clipboard()

then using your code

df = df.replace(np.nan,0)
df = df.groupby(['home_team'])['arrests'].mean()

df.plot.bar()



来源:https://stackoverflow.com/questions/40313727/bar-graph-from-dataframe-groupby

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!