遍历大熊猫数据帧的行时,print()输出显示它对第一行进行了两次迭代。但是,返回命令的最终输出是正确的。输出包含2行。为什么这样?
data = [
(24, 25, 100, "Pikachu"),
(55, 55, 120, "Bulbasaur")
]
columns = ["Power", "Speed", "HP", "Name"]
df = pd.DataFrame(data, columns = columns)
df
def total_stats(row):
print(row)
print()
return row
df.apply(total_stats, axis=1)