gpt4 book ai didi

python - 类型错误 : 'Index' object is not callable and SyntaxError: invalid syntax

转载 作者:太空宇宙 更新时间:2023-11-04 02:31:25 25 4
gpt4 key购买 nike

我需要帮助我从该站点下载的 csv 文件

https://catalog.data.gov/dataset/state-drug-utilization-data-2016我正在用 pandas 分析它,我需要到达文件中的列,然后执行此操作

import pandas as pd
url = "E:\dataset\state_dataset\Drug_Utilization_2017_-_California.csv"
df=pd.read_csv(url)
df.dropna(inplace=True)
df.shape
df.columns()

错误是

TypeError: 'Index' object is not callable

当我尝试了解文件中一列的类型时,我会这样做

    type(df.'state'[0])

“状态”是我的 csv 文件中的一列,错误是

SyntaxError: invalid syntax

很抱歉发送两种类型的错误,但我真的尝试了很多次但都失败了。

最佳答案

遵循有关如何使用 pandas 的教程可能会有所帮助:

df.columns

不可调用,您不能 df.columns() 它,因此 TypeError: 'Index' object is not callable

type(df.'state'[0])

不是您在 pandas 中获取列的方式,它们不是数据框的属性,您不能使用字符串作为属性名称,因此出现语法错误:

df['state'][0]

您将如何获得“状态”列中的第一项。

关于python - 类型错误 : 'Index' object is not callable and SyntaxError: invalid syntax,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49075166/

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