I am working on this dataset where I have used the sort_values()
function to get two distinct columns: the index
and the values
. I can even rename the index and the values columns. However, if I rename the dataset columns and assign everything to a new dataframe, I am not able to call the index column with the name that I assigned to it earlier.
pm_freq = df["payment_method"].value_counts()
pm_freq = pm_freq.head().to_frame()
pm_freq.index.name="Method"
pm_freq.rename(columns={"payment_method":"Frequency"},inplace=True)
pm_freq
Now I want to call it like this:
pm_freq["Method"]
But there's an error which states:
" KeyError: 'Method'"
Can someone please help me out with this?