Skip to content

Pandas

Usage

Get data

Read series from file

You can use

series = pd.read_csv('csvfile.csv', header = None, index_col = 0, squeeze = True)

squeeze also works with read_table.

DataFrame

Methods

to_sql

(https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_sql.html)(name, con, schema=None, if_exists='fail', index=True, index_label=None, chunksize=None, dtype=None, method=None) writes records stored in a DataFrame to a SQL database.

Example:

import pandas as pd
from sqlalchemy import create_engine

engine = create_engine('sqlite://', echo=False)
df = pd.DataFrame({'name' : })
df.to_sql('users', con=engine)

This will create a new table called users and fill it with the DataFrame. If the table already exists, it will fail. Set if_exists='append' or if_exists='replace' for other behaviors.

Debug

pandas.errors.DtypeWarning

Warning raised when reading different dtypes in a column from a file.

Reference