I have a DataFrame with an index column as [0, 1,2, … 11]. I would like to change it to [‘Jan’, ‘Feb’, …‘Dec’]. how do I do this?
Hi @vivek22 ,
df = pd.DataFrame(data=data)
# change the columns of dataframe
df.columns = ["Jan", "Feb", …"Dec"]
Hope this help.
I tried that but the index does not change.
I think confusion here may be you are thinking [0, 1, …] are columns. They are not, they are the row elements of Index column that need to be changed to [‘Jan’, ‘Feb’ …]
Hi @vivek22 ,
Oh so sorry, is it index column right ?
# add your name of months as a new column to your dataframe, for example a column named`month`
df["month"] = ["Jan", "Feb" …]
# Set the index column to `month` column
df = df.set_index(['month'])
Hope this help.
2 Likes
Thanks a lot! And apologize for the late response due to other commitments.
Hi @vivek22 ,
I am happy to help. ![]()
2 Likes