Python 数据帧的数据类型问题

Python 数据帧的数据类型问题,python,pandas,dataframe,Python,Pandas,Dataframe,我已将CSV文件读入pandas数据框,并尝试对数据进行一些分析。但是,我对“项目”列有问题。看起来该特定列已作为与其他列不同的数据类型读入。当我尝试使用astype更改数据类型时,出现错误“function”对象没有属性“astype”。你知道为什么这个特定的列会被作为不同的数据类型读入吗 data = pd.read_csv("/Volumes/Toshiba/GPRD/general-practice-prescribing-data/T201605PDPI+BNFT.csv") pri

我已将CSV文件读入pandas数据框,并尝试对数据进行一些分析。但是,我对“项目”列有问题。看起来该特定列已作为与其他列不同的数据类型读入。当我尝试使用astype更改数据类型时,出现错误“function”对象没有属性“astype”。你知道为什么这个特定的列会被作为不同的数据类型读入吗

data = pd.read_csv("/Volumes/Toshiba/GPRD/general-practice-prescribing-data/T201605PDPI+BNFT.csv")

print(data.head(10))
print(type(data.quantity))
print(type(data.items))
print(type(data.practice))
print(type(data.bnf_code))
print(type(data.bnf_name))
print(type(data.nic))
print(type(data.act_cost))

practice  bnf_code  bnf_name  items     nic  act_cost  quantity
0      5668      8092       592      2   44.10     40.84       189
1      1596     17512     16983      2    1.64      1.64        35
2      1596     25587     16124      1    1.26      1.28        42
3      1596     12551      1282      2    0.86      1.02        42
4      1596     18938     10575      1    1.85      1.82        56
5      1596      8777     21507      1    3.31      3.18        56
6      1596      9369     12008      1   63.15     58.56        56
7      1596     27926     17643      2  158.66    147.07        56
8      1596     26148     10230      1    0.35      0.44        14
9      1596      9148      3381      1    0.26      0.35         7
<class 'pandas.core.series.Series'>
<class 'method'>
<class 'pandas.core.series.Series'>
<class 'pandas.core.series.Series'>
<class 'pandas.core.series.Series'>
<class 'pandas.core.series.Series'>
<class 'pandas.core.series.Series'>
df.items是熊猫中的一个,请使用typedf[col_name]


为了最大限度地利用网站,重要的是,这包括创建一个示例。尝试使用数据['items']。data.items是数据框的一种方法,如您的输出所示。谢谢!那很有效!正如埃弗特所说,数据[‘项目’]将起作用。使用点语法访问列是一种快捷方式,并不总是有效。这种情况下,是数据帧方法或属性的名称、带空格的名称等特殊单词。。。
df=pd.DataFrame({"items":["1","3"]})

type(df.items)
Out[184]:
method
In [185]:
type(df["items"])
Out[185]:
pandas.core.series.Series