Bar graph from dataframe groupby

2019-06-18 22:37发布

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条回答
孤傲高冷的网名
2楼-- · 2019-06-18 23:33

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()

enter image description here

查看更多
登录 后发表回答