Import CSV File into Pandas Dataframe
Import data from the "orders.csv" file into a Pandas dataframe. Here we will parse the field "Order_Date" as a date, take a subset of columns and only import the first 500 rows.
import pandas as pd
orders = pd.read_csv('data/orders.csv', parse_dates=['Order_Date'],
usecols=['Order_No', 'Order_Date','ProductID'], nrows=500)
Import Excel Worksheet into Pandas Dataframe
Import data from the xlsx file "Returns.xslx" into a Pandas dataframe. The data in this case is stored in the "Returns" worksheet.
returns = pd.read_excel('data/Returns.xlsx', sheet_name='Returns')
Import Pickle File into Pandas Dataframe
df = pd.read_pickle('data/input.pkl')
Import SQL Server Query into Pandas Dataframe
Connect to SQL Server, run SQL query and import the resulting data into a Pandas dataframe. Note, this assumes that you don't have to enter a username and password to connect to the server you are querying.
import pandas as pd
import pyodbc as db
conn = db.connect('DRIVER={ODBC Driver 13 for SQL Server};SERVER=ST787554;
Trusted_Connection=yes;DATABASE=Orders')
qry = 'SELECT * FROM SALE_ITEMS'
sale_items = pd.read_sql(qry, conn)