Getting started with Pandas in Python II – Plotting datasets

Let us visualize how the coffees column change in the dataset –

data.coffees.plot()

Pandas Plot Line Graph

data.plot(x="timestamp", style=".-")
# Try this if the above fails -
# data.plot(x=data.timestamp, style=".-")

Pandas Plot DateTime

data.tail(n=10)
timestamp coffees contributor
661 2013-03-04 11:12:00 17793 Quentin
662 2013-03-04 16:43:00 17824 Quentin
663 2013-03-05 10:42:00 17852 Quentin
664 2013-03-05 13:29:00 17868 Quentin
665 2013-03-08 10:28:00 18062 Quentin
666 2013-03-12 08:28:00 18235 Sergio
667 2013-04-05 11:20:00 18942 Sergio
668 2013-04-27 11:04:00 19698 Sergio
669 2013-09-12 15:38:00 24450 Quentin
670 2013-09-13 10:28:00 24463 Quentin
data = data[data.timestamp < "2013-03-01"]
data.tail()
timestamp coffees contributor
655 2013-02-21 13:44:00 17345 Quentin
656 2013-02-21 15:02:00 17354 Quentin
657 2013-02-25 13:33:00 17468 Quentin
658 2013-02-25 17:25:00 17489 Quentin
659 2013-02-27 09:33:00 17564 Quentin
data.plot(x=data.timestamp, style=".-")

Pandas Plot DateTime Stripped

data.contributor.value_counts()
Quentin    354
Mike       152
Sergio      89
Mike M      29
Colm        12
Anthony      4
Ben          3
Stefano      2
Arturo       1
Name: contributor, dtype: int64
data.contributor.value_counts().plot(kind="bar")

Pandas Plot Bar Graph

weekday_names = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
weekday_dict = {key: weekday_names[key] for key in range(7)}
data.weekdays = data.weekdays.apply(lambda x: weekday_dict[x])
data.head()
timestamp coffees contributor weekdays
0 2011-10-03 08:22:00 397 Quentin Monday
1 2011-10-04 11:48:00 410 Quentin Tuesday
4 2011-10-05 10:47:00 464 Quentin Wednesday
5 2011-10-05 13:15:00 481 Quentin Wednesday
6 2011-10-06 07:21:00 503 Anthony Thursday
weekday_counts = data.groupby("weekdays").count()
weekday_counts = weekday_counts.loc[weekday_names]
weekday_counts
timestamp coffees contributor
weekdays
Monday 145 145 145
Tuesday 97 97 97
Wednesday 131 131 131
Thursday 117 117 117
Friday 114 114 114
Saturday 29 29 29
Sunday 13 13 13
weekday_counts.timestamp.plot(kind="bar", title="Datapoints added on each weekday")

Pandas Plot Weekdays

print("Hello World")