跳到内容

pandas-use-of-dot-ix (PD007)

源自 pandas-vet linter。

作用

检查 Pandas 对象中 .ix 的使用。

为什么这不好?

.ix 方法已被弃用,因为其行为含糊不清。具体来说,通常不清楚 .ix 是按标签索引还是按序号位置索引。

相反,首选使用 .loc 方法进行基于标签的索引,并使用 .iloc 进行序号索引。

示例

import pandas as pd

students_df = pd.read_csv("students.csv")
students_df.ix[0]  # 0th row or row with label 0?

建议改为

import pandas as pd

students_df = pd.read_csv("students.csv")
students_df.iloc[0]  # 0th row.

参考