Lowercase in Python

.lower() is a built-in Python method primarily used for string handling. The .lower() method takes no arguments and returns the lowercased strings from the given string by converting each uppercase character to lowercase. If there are no uppercase characters in the given string, it returns the original string.

.str.lower() method

In the below example, we will use the .str.lower() method which turns all column entries into lowercase characters. Here is what the list looks like to start with:

            name      price_usd
0          Apple           0.88
1         Banana           0.23
2         Orange           0.68
3     Watermelon           3.98
4           Plum           0.96
5    Blueberries           5.16
6    Dragonfruit           5.27
7           Kiwi           1.12

Now, select the name column from the fruit_price dataframe and apply .str.lower() to convert the name column entries into lowercase, as shown below.

fruit_price['name'] = fruit_price['name'].str.lower()

            name      price_usd
0          apple           0.88
1         banana           0.23
2         orange           0.68
3     watermelon           3.98
4           plum           0.96
5    blueberries           5.16
6    dragonfruit           5.27
7           kiwi           1.12

Interactive Example of str.lower()

In this example, all you need to do is use the right method to change the movie_title column to lower case using the .str.lower() method.

# Change movie_title column to lower lower case
movies['movie_title'] = movies['movie_title'].str.lower()

# Look at the change

When you run the above code, it produces the following result:

                       movie_title movie_genre  movie_length
0              the sumif all fears      Action           124
1             the seaborn identity      Action           119
2                     the matrices      Action           136
3  there's something about merging      Comedy           119
4                    mamma median!      Comedy           108
5                    harry plotter        Kids           159
6                   kung fu pandas        Kids            92
7           while you were sorting     Romance           103
8      10 things i hate about unix     Romance            97

Try it for yourself.

To learn more about putting pandas dataframe together in Python, please see this video from our course Python for Spreadsheet Users.

This content is taken from DataCamp’s Python for Spreadsheet Users course by Chris Cardillo.