Martin Kavalar / Feb 06 2019

Pandas Dataframe

This makes pandas data frames display as tables.

def __is_pandas_dataframe(value): 
  try:
    import pandas 
    return isinstance(value, pandas.DataFrame) 
  except: 
    return False 
  
def __write_dataframe(df, path): 
  df.to_csv(path) 
  return {'content-type': 'text/csv', 'kind': 'table'} 

register_coder('pandas', lambda value: __is_pandas_dataframe(value), lambda value, path: __write_dataframe(value, path))
import pandas as pd
d = {'First Column': [1, 2], 'Second Column': [3, 4]}
df = pd.DataFrame(data=d)
df