Reputation: 21
I have a dataframe with 100+ rows, where i need to extract values w.r.t 'High' column using groupby. But I am unable to do it.
My dataframe sample is:
Date Open High ... Volume
Date Open High ... Volume
0 24-04-2020 1840.10 1851.60 ... 93384
1 23-04-2020 1786.00 1891.70 ... 453645
2 22-04-2020 1746.00 1789.10 ... 103696
3 21-04-2020 1775.00 1794.00 ... 149222
I have stored the dataframe in a variable data_frame
and when I try using data_frame.groupby('High')
, I am getting the following error message:
"ValueError: Grouper for 'High' not 1-dimensional".
Any idea how I can fix this?
Upvotes: 0
Views: 603
Reputation: 11
I think the problem is with the header, the header has multi-index and so specifying only one column name gives you error.
You can set the column headers using the df.columns
. If you want to access the High
column, then simple use loc
or `data_frame['High']
data_frame.columns = ['Date', 'Open', 'High', 'Volume'] #add more
If you want to get the max value of the High
column based on the date, then you have to use groupby on Date
and project the High
column.
data_frame.groupby(['Date'])['High'].max()
Upvotes: 1