Pandas For All - Some Basic Pandas Functions
It has been quite a few days I have been working with Pandas and apparently I feel I have gotten quite good at it. (Quite a Braggard I know) So thought about adding a post about Pandas usage here. I intend to make this post quite practical and since I find the pandas syntax quite self explanatory, I won’t be explaining much of the codes. Just the use cases and the code to achieve them.
1. Import Pandas
We Start by importing the libraries that we will need to use.
import pandas as pd
2. Read a Datasource:
# Read from csv data files
# With Header
df = pd.read_csv("/Users/ragarw5/Downloads/SalesJan2009.csv")
# Without Header. sep param to provide the delimiter
df = pd.read_csv("/Users/ragarw5/Downloads/SalesJan2009.csv", header=None, sep= ",")
# Reading from SQL Datasource
import MySQLdb
from pandas import DataFrame
from pandas.io.sql import read_sql
db = MySQLdb.connect(host="localhost", # your host, usually localhost
user="root", # your username
…
Keep reading with a 7-day free trial
Subscribe to MLWhiz | AI Unwrapped to keep reading this post and get 7 days of free access to the full post archives.