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