删除 Pandas 中 DataFrame 的前三行
要删除Pandas中DataFrame的前三行,我们可以使用iloc()方法。
步骤
创建二维、大小可变、潜在异构的表格数据df。
打印输入数据帧df。
使用df.iloc[3:]删除前三行。
打印更新的DataFrame。
示例
import pandas as pd
df = pd.DataFrame(
{
"x": [5, 2, 7, 0, 7, 0, 5, 2],
"y": [4, 7, 5, 1, 5, 1, 4, 7],
"z": [9, 3, 5, 1, 5, 1, 9, 3]
}
)
print "Input DataFrame is:\n", df
df = df.iloc[3:]
print "After deleting the first 3 rows: \n", df输出结果Input DataFrame is: x y z 0 5 4 9 1 2 7 3 2 7 5 5 3 0 1 1 4 7 5 5 5 0 1 1 6 5 4 9 7 2 7 3 After deleting the first 3 rows: x y z 3 0 1 1 4 7 5 5 5 0 1 1 6 5 4 9 7 2 7 3
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短