drop first row of a dataframe in python

To drop the first row of a pandas DataFrame in Python, you can use the drop function combined with the index parameter.

Here's an example:

main.py
import pandas as pd

# Creating a sample DataFrame
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9]})

# Dropping the first row
df = df.drop(df.index[0])

# Outputting the updated DataFrame
print(df)
217 chars
11 lines

This will remove the first row from the DataFrame, resulting in:

main.py
   A  B  C
1  2  5  8
2  3  6  9
33 chars
4 lines

Note that the index parameter in the drop function expects the index or label of the row you want to drop. In this case, df.index[0] refers to the first row.

related categories

gistlibby LogSnag