'What is the python equivalent for names() function in R
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 ;-;
Solution 1:[1]
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')
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
