Converting characters of column values to

.str.lower: Converts all characters to lowercase

.str.upper: Converts all characters to uppercase

.str.title: Converts first character of each word to uppercase and remaining to lowercase

.str.capitalize: Converts first character to uppercase and remaining to lowercase

.str.swapcase: Converts uppercase to lowercase and lowercase to uppercase

.str.casefold: Removes all case distinctions in the string

source

In [20]:
import pandas as pd

df = pd.read_csv('amazon_fires.csv', encoding = "ISO-8859-1")

new_column_name = { 'ano' : 'year' ,  'mes': 'month', 'estado': 'state',
                   'numero': 'fire_numbers','encontro': 'date'}
                                                
df.rename(columns= new_column_name , inplace=True)   

Month_in_English = {'Janeiro': 'January',
'Fevereiro': 'February',
'Março': 'March',
'Abril': 'April',
'Maio': 'May',
'Junho': 'June',
'Julho': 'July',
'Agosto': 'August',
'Setembro': 'September',
'Outubro': 'October',
'Novembro': 'November',
'Dezembro': 'December'}

df["month"] = df["month"].map(Month_in_English)

new_column_order = [4,1,0,2,3,]

df = df[df.columns[new_column_order]]

df['fire_numbers'] = df['fire_numbers'].str.strip(" Fires")

df['fire_numbers'] = df['fire_numbers'].astype(float)

df = df.dropna() 

df.head()
Out[20]:
date month year state fire_numbers
0 1/1/1998 January 1998 Acre 0.0
1 1/1/1999 January 1999 Acre 0.0
2 1/1/2000 January 2000 Acre 0.0
3 1/1/2001 January 2001 Acre 0.0
4 1/1/2002 January 2002 Acre 0.0

Converts all characters to uppercase -> .str.upper

In [21]:
df['state'] = df['state'].str.upper()
## Converts all characters to lowercase -> .str.lower
df.head()
Out[21]:
date month year state fire_numbers
0 1/1/1998 January 1998 ACRE 0.0
1 1/1/1999 January 1999 ACRE 0.0
2 1/1/2000 January 2000 ACRE 0.0
3 1/1/2001 January 2001 ACRE 0.0
4 1/1/2002 January 2002 ACRE 0.0

Converts all characters to lowercase -> .str.lower

In [22]:
df['state'] = df['state'].str.lower()

df.head()
Out[22]:
date month year state fire_numbers
0 1/1/1998 January 1998 acre 0.0
1 1/1/1999 January 1999 acre 0.0
2 1/1/2000 January 2000 acre 0.0
3 1/1/2001 January 2001 acre 0.0
4 1/1/2002 January 2002 acre 0.0

Converts all characters to title -> .str.title

- title means converting first character of each word to uppercase and remaining to lowercase
In [23]:
df['state'] = df['state'].str.title()

df.head()
Out[23]:
date month year state fire_numbers
0 1/1/1998 January 1998 Acre 0.0
1 1/1/1999 January 1999 Acre 0.0
2 1/1/2000 January 2000 Acre 0.0
3 1/1/2001 January 2001 Acre 0.0
4 1/1/2002 January 2002 Acre 0.0

Converts all characters to capitalize -> .str.capitalize

- capitalize means converting first character to uppercase and remaining to lowercase
In [24]:
df['state'] = df['state'].str.capitalize()

df.head()
Out[24]:
date month year state fire_numbers
0 1/1/1998 January 1998 Acre 0.0
1 1/1/1999 January 1999 Acre 0.0
2 1/1/2000 January 2000 Acre 0.0
3 1/1/2001 January 2001 Acre 0.0
4 1/1/2002 January 2002 Acre 0.0

Converts all characters to swapcase -> .str.swapcase

- swapcase means converting uppercase to lowercase and lowercase to uppercase
In [25]:
df['state'] = df['state'].str.swapcase()

df.head()
Out[25]:
date month year state fire_numbers
0 1/1/1998 January 1998 aCRE 0.0
1 1/1/1999 January 1999 aCRE 0.0
2 1/1/2000 January 2000 aCRE 0.0
3 1/1/2001 January 2001 aCRE 0.0
4 1/1/2002 January 2002 aCRE 0.0

Converts all characters to casefold -> .str.casefold

- casefold means removing all case distinctions in the string
In [19]:
df['state'] = df['state'].str.casefold()

df.head()
Out[19]:
date month year state fire_numbers
0 1/1/1998 January 1998 acre 0.0
1 1/1/1999 January 1999 acre 0.0
2 1/1/2000 January 2000 acre 0.0
3 1/1/2001 January 2001 acre 0.0
4 1/1/2002 January 2002 acre 0.0