当可迭代的是数据帧时,“ for in”和“ if in”语句之间有什么区别?

时间:2019-12-29 18:29:59

标签: python pandas dataframe iterable

"Server: Cone\r\n"

输出

import pandas as pd

df = pd.DataFrame({"A": ["a", "b", "c"], "B": ["d", "e", "f"]})
print(df)
print(df["A"])

if "b" in df.A:
    print("if b in A")

for i in df.A:
    if i == "b":
        print("for b in A")

if 1 in df.A:
    print("if index in A")

似乎if-in使用数据帧的索引,for-in使用数据帧的值。为什么会有区别,到底有什么区别?

0 个答案:

没有答案