回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>读取数据集:</p>
<pre><code>visits= pd.read_csv('tracker.csv', low_memory=False, parse_dates=
['Date_Time'])
df= pd.DataFrame(visits)
</code></pre>
<p>数据的外观如下:</p>
^{pr2}$
<p>日期-时间列有问题:</p>
<pre><code>import datetime
df['new_date'] = [d.date() for d in df['Date_Time']]
df['new_time'] = [d.time() for d in df['Date_Time']]
df['year'] = pd.DatetimeIndex(df['new_date']).year
df['month'] = pd.DatetimeIndex(df['new_date']).month
</code></pre>
<p>目的是获得月=12,从1日到30日或31日或28日的所有天数,具体取决于月份。在</p>
<p>转换为下面的字符串并拆分值以访问拆分后的日值:</p>
<pre><code>strdt=str(df.new_date)
df['new_date']=df['new_date'].astype(str)
df['new_date']=df.new_date.apply(str)
type(df.new_date)
df['new_day']=df.new_date.str.split('-')
</code></pre>
<p>熊猫数据帧有1000多行,因此没有问题:</p>
<pre><code>print(df.new_day)
print(df.new_day)
0 [2016, 10, 18]
1 [2016, 10, 18]
2 [2016, 10, 18]
3 [2016, 10, 18]
4 [2016, 10, 18]
5 [2016, 10, 18]
6 [2016, 10, 19]
7 [2016, 10, 19]
8 [2016, 10, 19]
9 [2016, 10, 19]
10 [2016, 10, 19]
11 [2016, 10, 19]
12 [2016, 10, 19]
13 [2016, 10, 19]
14 [2016, 10, 19]
15 [2016, 10, 19]
16 [2016, 10, 19]
17 [2016, 10, 19]
18 [2016, 10, 20]
19 [2016, 10, 20]
20 [2016, 10, 20]
</code></pre>
<p>我想访问第二个逗号两位数后的第三个值
打印(df['new_day'][6][2])
十九</p>
<p>到目前为止还不错。。在</p>
<p>现在,我先用月份过滤日期,然后尝试访问第二个逗号后的值2位数字值,代码如下:</p>
<pre><code>value_list = [12]
vdf= pd.DataFrame(df[df.month.isin(value_list)])
print(vdf[:][:].head(n=1))
print(vdf[:][:].head(n=1))
Date_Time IPAddress Visitors OS Browser \
2836 2016-12-11 01:25:25 66.102.8.217 3955 Search Bot Apple Safari
Browser_Version Location Referrer \
2836 9 Florida, United States http://www.puneetmathur.in/
PageID new_date new_time year month new_day
2836 index.php 2016-12-11 01:25:25 2016 12 [2016, 12, 11]
</code></pre>
<p>当我试图访问第二个值时,它会给出奇怪的输出:</p>
<pre><code>vdf['new_day'][:][:2].str.split('-')
Out[250]: Series([], Name: new_day, dtype: object)
</code></pre>
<p>下面的内容也不能给出new_day第3列中第2个逗号后的所有值。
请告诉我如何访问“新”日第3列中的日期值</p>
<pre><code>vdf.iloc[:,:]
</code></pre>