i have a row that consists of days of the week but there is a random number in there and i just want to replace that number with "Thur" i tried . replace but my then all the other columns in my df disappeared except for the index and the column that had the days of the week
sales=sales["day of week"].replace(0, "Thru")
^^^this is the code i used
this is the df before i ran the code
This is the df after i ran the code
CodePudding user response:
You assign only the day of week column into sales, so it makes sense you get only one column. Try:
sales["day of week"]=sales["day of week"].replace(0, "Thru")
If it doesn't work (because day of week is an object type column), try:
sales["day of week"]=sales["day of week"].replace('0', "Thru")
CodePudding user response:
In pandas, replacing values can be done with .loc.
In your case the following should work:
sales.loc[sales["day of week"] == 0, "day of week"] = "Thru"

