【发布时间】:2017-05-06 14:47:14
【问题描述】:
如何访问数据集中 12 个月的所有天数?
数据的结构是:
print(df.head(n=1)) Date_Time IPAddress Visitors OS Browser \ 0 2016-10-18 12:57:45 104.236.233.18 1001 Mac OS Google Chrome Browser_Version Location Referrer PageID 0 39.0.2171.95 NaN creditcommerty.in index.php
为什么vdf在这段代码中索引值6和2:
print(vdf['new_day'][6][2])
给出这个错误?
print(vdf['new_day'][6][2])
Traceback (most recent call last):
File "<ipython-input-196-c01f93f97338>", line 1, in <module>
print(vdf['new_day'][6][2])
KeyError: 6
【问题讨论】:
-
您需要显示您的数据。目前没有提供足够的信息来提供帮助。
-
查看数据结构如下: print(df.head(n=1)) Date_Time IPAddress Visitor OS Browser \ 0 2016-10-18 12:57:45 104.236 .233.18 1001 Mac OS Google Chrome Browser_Version Location Referrer PageID 0 39.0.2171.95 NaN creditcommerty.in index.php
-
查看数据结构如下: print(df.head(n=1)) Date_Time IPAddress Visitor OS Browser \ 0 2016-10-18 12:57:45 104.236 .233.18 1001 Mac OS Google Chrome Browser_Version Location Referrer PageID 0 39.0.2171.95 NaN creditcommerty.in index.php
-
#获取第6行和第2两个值即DAY print(df['new_day'][6][2]) 19 value_list = [12] vdf= pd.DataFrame(df [df.month.isin(value_list)]) print(vdf.head(n=1)) 现在,当我尝试访问我之前所做的数据帧的 DAY 部分时,它会出现以下错误:
-
print(vdf['new_day'][6][2]) Traceback(最近一次调用最后一次):文件“
”,第 1 行,在 打印(vdf['new_day'][6][2]) KeyError: 6