1. Dropping a Row with specified index
2. Dropping Multiple Rows with specified indexes
3. Drop A Range of Rows with specified range
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()
df = df.drop(df.index[1])
df.head()
- We can use the drop parameter to avoid the old index being added as a column
df = df.reset_index()
df.head()
df = df.reset_index(drop=True)
df.head()
df = df.drop(df.index[[2,3]])
df = df.reset_index(drop=True)
df.head()
df = df.drop(df.index[[1,4]])
df.head()
df = df.drop(df.index[[1,4]])
df = df.reset_index(drop=True)
df.head()