Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!
In [1]:
import pandas as pd
In [2]:
df = pd.DataFrame(
{"col1": [1, 2], "col2": [0.5, 0.75]},
index=["row1", "row2"],
columns=["col1", "col2"],
)
df
Out[2]:
In [16]:
[m for m in dir(df) if m.startswith("to_")]
Out[16]:
DataFrame.to_dict¶
In [3]:
df.to_dict()
Out[3]:
In [5]:
df.to_dict("list")
Out[5]:
In [6]:
df.to_dict("series")
Out[6]:
In [7]:
df.to_dict("split")
Out[7]:
In [8]:
df.to_dict("records")
Out[8]:
In [13]:
df.to_dict("index")
Out[13]:
DataFrame.to_records¶
In [12]:
df.to_records()
Out[12]:
In [20]:
df.to_records(index=False)
Out[20]:
In [ ]: