Python for Data Science - Visualizing time series
Chapter 4 - Practical Data Visualization
Segment 5 - Visualizing time series
import numpy as np
from numpy.random import randn
import pandas as pd
from pandas import Series, DataFrame
import matplotlib.pyplot as plt
from pylab import rcParams
%matplotlib inline
rcParams['figure.figsize'] = 5, 4
The simplest time series plot
address = '~/Data/Superstore-Sales.csv'
df = pd.read_csv(address, index_col='Order Date',encoding='cp1252', parse_dates=True)
df.head()
Row ID | Order ID | Order Priority | Order Quantity | Sales | Discount | Ship Mode | Profit | Unit Price | Shipping Cost | Customer Name | Province | Region | Customer Segment | Product Category | Product Sub-Category | Product Name | Product Container | Product Base Margin | Ship Date | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Order Date | ||||||||||||||||||||
2010-10-13 | 1 | 3 | Low | 6 | 261.5400 | 0.04 | Regular Air | -213.25 | 38.94 | 35.00 | Muhammed MacIntyre | Nunavut | Nunavut | Small Business | Office Supplies | Storage & Organization | Eldon Base for stackable storage shelf, platinum | Large Box | 0.80 | 10/20/2010 |
2012-10-01 | 49 | 293 | High | 49 | 10123.0200 | 0.07 | Delivery Truck | 457.81 | 208.16 | 68.02 | Barry French | Nunavut | Nunavut | Consumer | Office Supplies | Appliances | 1.7 Cubic Foot Compact "Cube" Office Refrigera... | Jumbo Drum | 0.58 | 10/2/2012 |
2012-10-01 | 50 | 293 | High | 27 | 244.5700 | 0.01 | Regular Air | 46.71 | 8.69 | 2.99 | Barry French | Nunavut | Nunavut | Consumer | Office Supplies | Binders and Binder Accessories | Cardinal Slant-D® Ring Binder, Heavy Gauge Vinyl | Small Box | 0.39 | 10/3/2012 |
2011-07-10 | 80 | 483 | High | 30 | 4965.7595 | 0.08 | Regular Air | 1198.97 | 195.99 | 3.99 | Clay Rozendal | Nunavut | Nunavut | Corporate | Technology | Telephones and Communication | R380 | Small Box | 0.58 | 7/12/2011 |
2010-08-28 | 85 | 515 | Not Specified | 19 | 394.2700 | 0.08 | Regular Air | 30.94 | 21.78 | 5.94 | Carlos Soltero | Nunavut | Nunavut | Consumer | Office Supplies | Appliances | Holmes HEPA Air Purifier | Medium Box | 0.50 | 8/30/2010 |
df['Order Quantity'].plot()
<matplotlib.axes._subplots.AxesSubplot at 0x7eff835be588>
df2 = df.sample(n=100, random_state=25, axis=0)
plt.xlabel('Order Date')
plt.ylabel('Order Quantity')
plt.title('Superstore Sales')
df2['Order Quantity'].plot()
<matplotlib.axes._subplots.AxesSubplot at 0x7eff8145ce10>
相信未来 - 该面对的绝不逃避,该执著的永不怨悔,该舍弃的不再留念,该珍惜的好好把握。