I would like to rename the Weekday
to day_of_week
in dataframe below
Weekday Value
2 10
2 5
8 50
7 20
4 11
using
df = df.rename(columns = {'Weekday' : 'day_of_week'})
I then notice that df
has been converted to pandas.core.series.Series
from DataFrame
, which is not what I meant, because I would like to replace all 8
with 1
in the column in a DataFrame
, and I'm not sure how to do it with a series
.
My question is:
1) what are the different ways of renaming a column in a pandas dataframe and the differences(regarding data type transformation)?
2) what is the best way to solve the problem in my case and how to do it?
Thanks
Update:
Sorry the problem lies with replacing values 8
with 1
in column day_of_week
after renaming.
New problem: I used
df['day_of_week'].replace(['8'], '1')
df['day_of_week'].describe()
and it showed that the values had not changed. What's the correct way of doing this?