Issue
I want to plot a histogram for two columns of my Pandas DataFrame.
Bins are defined on a ratio
column, e.g. [0-0.1, 0.1-0.2,...,0.9-1.0], and I want to plot the mean value of another column called feet
for each bin.
Is there a way to just plot the histogram without generating a new column ?
Solution
You don't need to create a new column, just pass a function to groupby:
Example:
import pandas as pd
import numpy as np
df = pd.DataFrame({'ratio':np.random.rand(100), 'feet': np.random.rand(100)*10})
df.groupby(pd.cut(df.ratio, np.linspace(0,1,11))).feet.mean().plot.bar()
PS: Starting with version 1.1.0 of pandas you can directly specify the y label like ...plot.bar(ylabel='Mean feet')
.
Answered By - Stef
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.