gpt4 book ai didi

Python pandas 引用带有 "/"的列

转载 作者:行者123 更新时间:2023-11-30 22:46:13 24 4
gpt4 key购买 nike

我正在使用 pandas 从 Excel 文件中读取数据。我只想查看已访问过的某个区域的数据。

我在电子表格中标记为“VISIT(Y/N)”的访问列中收到以下错误:

AttributeError: 'DataFrame' object has no attribute 'VISIT'

这是我正在使用的代码。如何让 python 将“VISIT(Y/N)”解释为一列?

import pandas as pd

df=pd.read_excel("myFile.xlsx")

data = df[(df.REGION == "AMER") & df.VISIT(Y/N) == "Y")]

print(list(df))
print(data)

最佳答案

不要使用您发现无效的 df.VISIT(Y/N),而是执行以下操作:

df['VISIT(Y/N)'] == "Y"

关于Python pandas 引用带有 "/"的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40938312/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com