The to_pandas() function creates a pandas DataFrame from a teradataml DataFrame.
Column types of the resulting Pandas DataFrame depends on pandas.read_sql_query().
Examples Prerequisite
Assume a teradataml DataFrame "df" is created from a Vantage table "sales", using command:
df = DataFrame("sales")
Example: Create a pandas DataFrame without specifying index
>>> pandas_df = df.to_pandas()
>>> pandas_df Feb Jan Mar Apr datetime accounts Alpha Co 210 200 215 250 2017-04-01 Blue Inc 90 50 95 101 2017-04-01 Yellow Inc 90 None None None 2017-04-01 Jones LLC 200 150 140 180 2017-04-01 Red Inc 200 150 140 None 2017-04-01 Orange Inc 210 None None 250 2017-04-01
Example: Create a pandas DataFrame using index_column to set the index to "Feb"
>>> pandas_df = df.to_pandas(index_column = 'Feb')
>>> pandas_df accounts Jan Mar Apr datetime Feb 210 Alpha Co 200 215 250 2017-04-01 90 Blue Inc 50 95 101 2017-04-01 90 Yellow Inc None None None 2017-04-01 200 Jones LLC 150 140 180 2017-04-01 200 Red Inc 150 140 None 2017-04-01 210 Orange Inc None None 250 2017-04-01
Example: Create a pandas DataFrame using a list of column names for a multi-column index
>>> pandas_df = df.to_pandas(index_column = ['accounts', 'Feb'])
>>> pandas_df Jan Mar Apr datetime accounts Feb Yellow Inc 90 None None None 2017-04-01 Alpha Co 210 200 215 250 2017-04-01 Jones LLC 200 150 140 180 2017-04-01 Orange Inc 210 None None 250 2017-04-01 Blue Inc 90 50 95 101 2017-04-01 Red Inc 200 150 140 None 2017-04-01
Example: Create a pandas DataFrame using num_rows to limit the number of rows to 3
>>> pandas_df = df.to_pandas(index_column = 'Feb', num_rows = 3)
>>> pandas_df accounts Jan Mar Apr datetime Feb 90.0 Yellow Inc NaN NaN NaN 2017-01-04 90.0 Blue Inc 50.0 95.0 101.0 2017-01-04 200.0 Red Inc 150.0 140.0 NaN 2017-01-04