import pandas as pd
df = pd.DataFrame({"abc": [1,2,3], "def": [4,5,6]})
for d in df:
print(d)
给出:
abc
def
我认为你要做的事情可以通过以下方式实现:
df = pd.DataFrame({"genre": ["something", "soemthing else"], "abc": ["movie1", "movie2"]})
movies = df.to_dict("records")
[m["abc"] for m in movies if m["genre"] == "something"]
您的循环
for d in df
将为您的值提供标题。 您的d将具有泛型作为值。 尝试运行:-你会明白的
d是代码中的列名。这就是为什么会出现这个错误
请参见以下示例:
给出:
我认为你要做的事情可以通过以下方式实现:
其中:
相关问题 更多 >
编程相关推荐