The data module provides a very useful data.df_to_series(df, display=[])
function which allows you to easily explore an entire dataframe whithout having to make a multitude of different plots. It takes two arguments:
df
: A pandas dataframedisplay=[]
: An array containing the names of the columns for which you want the series display
property set to True
. These columns are plotted when the chart is shown while the other columns can still be added afterwards using the variable selector.Lets start by importing the necessary modules:
import charts
import pandas as pd
import numpy as np
start = pd.Timestamp("20150101")
end = pd.Timestamp("20150201")
index = pd.DatetimeIndex(freq='900S', start=start, end=end)
columns = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
data = np.zeros((26, len(index)))
for i, c in enumerate(columns):
data[i] = i*np.linspace(0, 100, len(index))
df = pd.DataFrame(index=index, columns=columns, data=data.T)
With charts.data.df_to_series()
we can easily convert the dataframe to a series object for the Charts library. To prevent the chart from having to render all 26 variables at the same time we ask it to only display A and C when it first renders.
series = charts.data.df_to_series(df, display=['A', 'G', 'Z'])
options = charts.options.default()
options['title'] = dict(text='Pandas dataframe example')
Next thing we plot the entire dataframe but only A and C are rendered initially. Note that you can easily add the other variables by typing in their name in the variable selector! Charts enables you to easily explore all of the data hidden in a pandas dataframe whithout having to write code for every every bit of information you want to see. Just type in the name of the column you would like to plot and use the zooming options to navigate!
charts.plot(series, options, height=500, stock=True, show='inline')