# Import pandas library
import pandas as pd
# initialize list of lists
data = [['tom', 10], ['nick', 15], ['juli', 14]]
# Create the pandas DataFrame
df = pd.DataFrame(data, columns = ['Name', 'AGE'])
I want to change on of the field AGE to age, keep Name unchanged .
How Can I do it?
Thanks,
Jeff
(Oct-29-2019, 03:42 PM)zhujp98 Wrote: [ -> ]# Import pandas library
import pandas as pd
# initialize list of lists
data = [['tom', 10], ['nick', 15], ['juli', 14]]
# Create the pandas DataFrame
df = pd.DataFrame(data, columns = ['Name', 'AGE'])
I want to change on of the field AGE to age, keep Name unchanged .
How Can I do it?
Thanks,
Jeff
Hi!
If I understand correctly, it is you who is creating the columns and giving the names of the columns with the line:
df = pd.DataFrame(data, columns = ['Name', 'AGE'])
so have you tried changing that line to:
df = pd.DataFrame(data, columns = ['Name', 'age'])
All the best,
Thanks,
I want to use program to do that.
The short code is just a simple example. I actually have a very large table with 50 columns. The dataframe is created from a .csv file. I want to change one of columns to lower case.
Thanks,
Jeff
If you are trying to change the name of the column, rather than the values of the column, you can use rename:
df.rename(columns = {'AGE': 'age'}, inplace = True)