I have the following df:
import pandas as pd
d = {
'Group': ['Month', 'Sport'],
'col1': [1, 'A'],
'col2': [4, 'B'],
'col3': [9, 'C']
}
df = pd.DataFrame(d)
I would like to convert all of the values in row index[0] excluding 'Month' to actual months. I've tried the following:
import datetime as dt
m_lst = []
for i in df.iloc[0]:
if type(i) != str:
x = dt.date(1900, i, 1).strftime('%B')
m_lst.append(x)
df.iloc[0][1:] = m_lst #(doesn't work)
So the for loop creates a list of months that correlate to the value in the dataframe. I just can't seem to figure out how to replace the original values with the values from the list. If there's an easier way of doing this, that would be great as well.