Convert whole dataframe from lower case to upper case with Pandas

前端 未结 6 801
忘掉有多难
忘掉有多难 2020-12-13 18:12

I have a dataframe like the one displayed below:

# Create an example dataframe about a fictional army
raw_data = {\'regiment\': [\'Nighthawks\', \'Nighthawk         


        
6条回答
  •  春和景丽
    2020-12-13 19:10

    Loops are very slow instead of using apply function to each and cell in a row, try to get columns names in a list and then loop over list of columns to convert each column text to lowercase.

    Code below is the vector operation which is faster than apply function.

    for columns in dataset.columns:
        dataset[columns] = dataset[columns].str.lower() 
    

提交回复
热议问题