How to change a dataframe column to lower case - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: How to change a dataframe column to lower case (/thread-22098.html) |
How to change a dataframe column to lower case - zhujp98 - Oct-29-2019 # 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 RE: How to change a dataframe column to lower case - newbieAuggie2019 - Oct-29-2019 (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 . 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, RE: How to change a dataframe column to lower case - zhujp98 - Oct-29-2019 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 RE: How to change a dataframe column to lower case - newbieAuggie2019 - Oct-29-2019 (Oct-29-2019, 04:11 PM)zhujp98 Wrote: I want to change one of columns to lower case. Hi again! Then maybe you could use something like: df['AGE'].str.lower()and if it is for all the columns, you could use something like: data.columns = [x.lower() for x in data.columns]I have based my answer on these: https://stackoverflow.com/questions/22245171/how-to-lowercase-a-pandas-dataframe-string-column-if-it-has-missing-values https://stackoverflow.com/questions/19726029/how-can-i-make-pandas-dataframe-column-headers-all-lowercase All the best, RE: How to change a dataframe column to lower case - ichabod801 - Oct-29-2019 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) RE: How to change a dataframe column to lower case - zhujp98 - Oct-29-2019 thanks! |