熊猫时间序列:如何仅绘制一天中的时间(无日期)与其他值?

Fab*_*ler 1 python time-series matplotlib pandas

当我准备对一个相当大的数据集做一些回归时,我想首先想象数据.

我们正在讨论的数据是2011年5月纽约地铁的数据(每小时参赛,下雨,天气等).

在创建数据帧时,我将小时和时间转换为pandas datetime格式.
现在我意识到,从手边的例子的逻辑观点来看,我想做的事情没有多大意义.但是,我仍然希望根据每小时条目绘制确切的时间.正如我所说的那样,因为ENTRIESn_hourly是聚合的,所以这并不是很有意义.但是,为了论证,假设ENTRIESn_hourly将与确切的时间戳明确相关.

现在,我将如何只花时间而忽略日期,然后将其描绘出来?

请在这里找到jupyter笔记本:https://github.com/FBosler/Udacity/blob/master/Example.ipynb

多谢!

Max*_*axU 5

IIUC你可以这样做:

In [9]: weather_turnstile.plot.line(x=weather_turnstile.Date_Time.dt.time, y='ENTRIESn_hourly', marker='o', alpha=0.3)
Out[9]: <matplotlib.axes._subplots.AxesSubplot at 0xc2a63c8>
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

.dt访问器使您可以访问以下属性:

In [10]: weather_turnstile.Date_Time.dt.
weather_turnstile.Date_Time.dt.ceil             weather_turnstile.Date_Time.dt.is_quarter_end   weather_turnstile.Date_Time.dt.strftime
weather_turnstile.Date_Time.dt.date             weather_turnstile.Date_Time.dt.is_quarter_start weather_turnstile.Date_Time.dt.time
weather_turnstile.Date_Time.dt.day              weather_turnstile.Date_Time.dt.is_year_end      weather_turnstile.Date_Time.dt.to_period
weather_turnstile.Date_Time.dt.dayofweek        weather_turnstile.Date_Time.dt.is_year_start    weather_turnstile.Date_Time.dt.to_pydatetime
weather_turnstile.Date_Time.dt.dayofyear        weather_turnstile.Date_Time.dt.microsecond      weather_turnstile.Date_Time.dt.tz
weather_turnstile.Date_Time.dt.days_in_month    weather_turnstile.Date_Time.dt.minute           weather_turnstile.Date_Time.dt.tz_convert
weather_turnstile.Date_Time.dt.daysinmonth      weather_turnstile.Date_Time.dt.month            weather_turnstile.Date_Time.dt.tz_localize
weather_turnstile.Date_Time.dt.floor            weather_turnstile.Date_Time.dt.nanosecond       weather_turnstile.Date_Time.dt.week
weather_turnstile.Date_Time.dt.freq             weather_turnstile.Date_Time.dt.normalize        weather_turnstile.Date_Time.dt.weekday
weather_turnstile.Date_Time.dt.hour             weather_turnstile.Date_Time.dt.quarter          weather_turnstile.Date_Time.dt.weekday_name
weather_turnstile.Date_Time.dt.is_month_end     weather_turnstile.Date_Time.dt.round            weather_turnstile.Date_Time.dt.weekofyear
weather_turnstile.Date_Time.dt.is_month_start   weather_turnstile.Date_Time.dt.second           weather_turnstile.Date_Time.dt.year
Run Code Online (Sandbox Code Playgroud)

  • 仅供参考:http://pandas.pydata.org/pandas-docs/version/0.18.1/api.html#datetimelike-properties (2认同)