how to drop the first row of a dataframe in python

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

Here's an example:

main.py
import pandas as pd

# Create a sample DataFrame
data = {'Column1': [1, 2, 3, 4],
        'Column2': ['A', 'B', 'C', 'D']}
df = pd.DataFrame(data)

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

# Print the updated DataFrame
print(df)
236 chars
13 lines

This will output the DataFrame without the first row:

main.py
   Column1 Column2
1        2       B
2        3       C
3        4       D
76 chars
5 lines

By specifying df.index[0] as the index parameter in the drop method, the first row of the DataFrame will be removed and the DataFrame will be updated accordingly.

related categories

gistlibby LogSnag