Reputation: 1
I have a code in R, where in the data frame "inputdata" there are multiple columns, and we are replacing the word "new" with "old" in the entire data frame:
names(inputData)[names(inputData)=="new"] <- "old"
How do I perform the same function in python, im a newbie in python ;-;
Upvotes: 0
Views: 172
Reputation: 416
First of all welcome to the world of python. Try this https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.replace.html
for e.g.
df = pd.DataFrame({'A': [0, 1, 2, 3, 4],
'B': [5, 6, 7, 8, 9],
'C': ['a', 'b', 'c', 'd', 'e']})
df.replace(0, 5)
BTW if you are looking for just column names update then do below:
df.columns = df.columns.str.replace('new', 'old')
Upvotes: 1