Data Wrangling
Importing Data Select, Drop & Rename Filter, Sort & Sample Add Columns Cleaning Data Dates & Time Join Data Aggregate & Transform
Data Analysis
Exploring Data Plotting Continuous Variables Plotting Discrete Variables
Machine Learning
Data Preparation Linear Models
Other Tutorials & Content
Learn Python for Data Science Learn Alteryx Blog



Importing Data into Pandas Dataframes

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

#Connect to SQL Server using ODBC Driver 13 for SQL Server.
#You may need to declare a different driver depending on the server you are connecting to.
conn = db.connect('DRIVER={ODBC Driver 13 for SQL Server};SERVER=ST787554;
Trusted_Connection=yes;DATABASE=Orders')

#Declare SQL Query
qry = 'SELECT * FROM SALE_ITEMS'

#Run query and import data into Pandas dataframe
sale_items = pd.read_sql(qry, conn)