Search code examples
pythonpandasfunctiondataframelowercase

How to lowercase an entire Data Frame?


I'm' trying to build a function to the job because my data frames are in a list. This is the function that I am working on:

def lower(x):
        
        '''
        
        This function lowercase the entire Data Frame.
        
        '''
        
        for x in clean_lst:
            for x.columns in x:
                x.columns['i'].map(lambda i: i.lower())

It's not working like that!

This is the list of data frames:

clean_lst = [pop_movies, trash_movies]

I am planing to access the list like this:

lower = [pd.DataFrame(lower(x)) for x in clean_list] 
pop_movies = lower[0] 
trash_movies = lower[1]

HELP!!!


Solution

  • You can use apply functions from pandas package which works on df / series.

    clean_lst = [i.apply(lambda x: x.str.lower()) for i in clean_lst]