I am trying to process some .csv data using pandas, and I am struggling with something that I am sure is a rookie move, but after spending a lot of time trying to make this work, I need your help.
Essentially, I am trying to find the index of a value within a dataframe I have created.
max = cd_gross_revenue.max()
#max value of the cd_gross_revenue dataframe
print max
#finds max value, no problem!
maxindex = cd_gross_revenue.idxmax()
print maxindex
#finds index of max_value, what I wanted!
print max.index
#ERROR: AttributeError: 'numpy.float64' object has no attribute 'index'
The maxindex variable gets me the answer using idxmax(), but what if I am not looking for the index of a max value? What if it is some random value's index that I am looking at, how would I go about it? Clearly .index does not work for me here.
Thanks in advance for any help!
df.loc[df.col == max].indexwould return you the indexTraceback (most recent call last): File "psims2.py", line 81, in <module> print cd_gross_revenue.loc[cd_gross_revenue.col == max].index File "C:\Python27\lib\site-packages\pandas-0.14.1-py2.7-win32.egg\pandas\core\generic.py", line 18 43, in __getattr__ (type(self).__name__, name)) AttributeError: 'Series' object has no attribute 'col'colwas a generic name for your column of interest so substitute the column name with the one from your df, my question is how many columns does this df have and is there only 1 or do you know which column has the max value, if so the subsitutecolwith that name