Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
392 views
in Technique[技术] by (71.8m points)

pandas - 熊猫df histo,格式化我的x代码,并包含空白(Pandas df histo, format my x ticker and include empty)

I got this pandas df:

(我得到了这个熊猫df:)

index      TIME
12:07      2019-06-03  12:07:28
10:04      2019-06-04  10:04:25
11:14      2019-06-09  11:14:25
...

I use this command to do an histogram to plot how much occurence for each 15min periods

(我使用此命令进行直方图绘制每15分钟的发生次数)

df['TIME'].groupby([df["TIME"].dt.hour, df["TIME"].dt.minute]).count().plot(kind="bar")

my plot look like this:

(我的情节看起来像这样:)

在此处输入图片说明

How can I get x tick like 10:15 in lieu of (10, 15) and how manage to add x tick missing like 9:15, 9:30... to get a complet time line??

(我怎样才能像10:15一样获得x刻度来代替(10,15),以及如何设法像9:15、9:30那样添加x刻度缺失……以获得完整的时间线?)

  ask by Jonathan Roy translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can resample your TIME column to 15 mins intervalls and count the number of rows.

(您可以将TIMEresample到15分钟间隔并计数行数。)

Then plot a regular bar chart.

(然后绘制常规条形图。)

df = pd.DataFrame({'TIME': pd.to_datetime('2019-01-01') + pd.to_timedelta(pd.np.random.rand(100) * 3, unit='h')})
df = df[df.TIME.dt.minute > 15] # make gap
df.resample('15T', on='TIME').count().plot.bar()

在此处输入图片说明


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...