I would like to delete all rows of my DataFrame except the first and the last one regardless of its size
Input
1
2
3
4
5
.
.
999999999
Expected output:
1
999999999
CodePudding user response:
You can use iloc
import pandas as pd
data = {
"Input": [1, 2, 3, 4, 5, 6, 7, 8]
}
df = pd.DataFrame(data)
print(f"{df}\n")
df = df.iloc[[0, -1]].reset_index(drop=True)
print(df)
Input
0 1
1 8