pandas: Reset index#
import pandas as pd
Loading data into Pandas DataFrame#
The dataset is from Kaggle - Pokemon.
data = pd.read_csv('data/Pokemon.csv')
data
In the cell below, you can see the index is not consecutive (the leftmost column). We can reset it with the reset_index()
method. By default, it adds the old index as a new column. If you do not want that, use the drop=True
parameter.
new_data = data.loc[(data['Type 1'] == 'Grass') | (data['Type 2'] == 'Poison')][0::10].loc[data['HP'] > 50].head(3)
new_data
new_data.reset_index(drop=True, inplace=True)
new_data