
pandas DataFrame drop - Remove rows
import pandas
people = [
('Einstein', 1879, 'physics'),
('Bohr', 1885, 'physics'),
('Weil', 1912, 'mathematics'),
('Keynes', 1883, 'economics'),
]
df = pandas.DataFrame(people, columns=['name', 'born', 'field'])
df = df.drop(index=[1, 2])
print(df)
# name born field
# 0 Einstein 1879 physics
# 3 Keynes 1883 economics
DataFrame's drop
removes rows. In the above case, the rows with index 1 or 2 are dropped from people.
Comments
Powered by Markdown