Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Convert pandas DataFrame to Other Format

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

Loading...
['to_clipboard', 'to_csv', 'to_dict', 'to_excel', 'to_feather', 'to_gbq', 'to_hdf', 'to_html', 'to_json', 'to_latex', 'to_markdown', 'to_numpy', 'to_parquet', 'to_period', 'to_pickle', 'to_records', 'to_sql', 'to_stata', 'to_string', 'to_timestamp', 'to_xarray', 'to_xml']

DataFrame.to_dict

{'col1': {'row1': 1, 'row2': 2}, 'col2': {'row1': 0.5, 'row2': 0.75}}
{'col1': [1, 2], 'col2': [0.5, 0.75]}
{'col1': row1 1 row2 2 Name: col1, dtype: int64, 'col2': row1 0.50 row2 0.75 Name: col2, dtype: float64}
{'index': ['row1', 'row2'], 'columns': ['col1', 'col2'], 'data': [[1, 0.5], [2, 0.75]]}
[{'col1': 1, 'col2': 0.5}, {'col1': 2, 'col2': 0.75}]
{'row1': {'col1': 1, 'col2': 0.5}, 'row2': {'col1': 2, 'col2': 0.75}}

DataFrame.to_records

rec.array([('row1', 1, 0.5 ), ('row2', 2, 0.75)], dtype=[('index', 'O'), ('col1', '<i8'), ('col2', '<f8')])
rec.array([(1, 0.5 ), (2, 0.75)], dtype=[('col1', '<i8'), ('col2', '<f8')])