I have a CSV
file with data that look like this:
Time Pressure
1/1/2017 0:00 5.8253
... ...
3/1/2017 0:10 4.2785
4/1/2017 0:20 5.20041
5/1/2017 0:30 4.40774
6/1/2017 0:40 4.03228
7/1/2017 0:50 5.011924
12/1/2017 1:00 3.9309888
I want to make a month-wise histogram (NORMALIZED) on the pressure data and finally write the plots into PDF. I understand that I need to use Groupby
and Numpy.hist
option,but I'm not sure how to use them. (I'm a newbie to Python). Please help!
CODE 1:
n = len(df) // 5
for tmp_df in (df[i:i+n] for i in range(0, len(df), n)):
gb_tmp = tmp_df.groupby(pd.Grouper(freq='M'))
ax = gb_tmp.hist()
plt.setp(ax.xaxis.get_ticklabels(),rotation=90)
plt.show()
plt.close()
This gives me the following error message:
ValueError: range() arg 3 must not be zero
CODE 2:
df1 = df.groupby(pd.Grouper(freq='M'))
np.histogram(df1,bins=10,range=None,normed=True)
This returns another error message:
ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
I tried the above codes, but got these errors. Not sure if I'm using it right.