Altair® Panopticon

 

Python Pandas DataFrame

With the Python connector, if the data is in a Pandas DataFrame, they need to be converted into a list of dictionaries. For example:

 

import pandas as pd

import numpy as np

 

# Creating the Data Frame

s = pd.Series([1,3,5,np.nan,6,8])

dates = pd.date_range('20130101', periods=6)

df = pd.DataFrame(np.random.randn(6,4), index=dates, columns=list('ABCD'))

return df

 

If, however, the Pandas DataFrame includes Numpy data types, they need to be additionally converted to standard Python data types. For example:

 

import pandas as pd

import numpy as np

 

# Creating the Data Frame

s = pd.Series([1,3,5,np.nan,6,8])

dates = pd.date_range('20130101', periods=6)

df = pd.DataFrame({ 'A' : 1.,

   'B' : pd.Timestamp('20130102'),

   'C' : pd.Series(1,index=list(range(4)),dtype='float32'),

   'D' : np.array([3] * 4,dtype='int32'),

   'E' : pd.Categorical(["test","train","test","train"]),

   'F' : 'foo' })

return df