Skip to content

Instantly share code, notes, and snippets.

@spepechen
spepechen / seaborn-charting.py
Created December 2, 2019 10:08
List down some common chart types I use recently first. I'll update this with example datasets
# multi linechart
# small multiple line charts
# heatmap - categorical
# heatmap - numeric
@spepechen
spepechen / pandas-helper.py
Last active December 3, 2019 03:45
Modularising some of my workflow after hanging out with pandas for quite some time
# helper func
def hi_frame(frame):
print('Nice meeting you!╰( ´・ω・)つ──☆✿✿✿✿✿✿')
print('A little bit abt me, I am...\n')
print('{row} rows X {col} columns'.format(row=frame.shape[0], col=frame.shape[1]))
print('==================================')
print(frame.dtypes)
return frame.head(5)
def hi_frames(frame, frame2):
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@spepechen
spepechen / pandas-worksheet-demo.ipynb
Last active July 25, 2017 08:22
Lab session 0725
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
# run this or you cannot see the viz
python -m SimpleHTTPServer 8000
@spepechen
spepechen / pandas-cheatsheet.py
Last active April 3, 2021 18:17
Handy pandas snippets! 🐼means in 0.24.2, others are still in older versions. I'm planning to update all soon. ----- Dec 2019
#### BASIC ########################################################################################################################
# 🐼cleaning str in the header
df.columns = [x.lower().strip() for x in df.columns] # lower case, trim leading and trailing spaces
df.columns = df.columns.str.replace(' ','') # remove all whitespaces
# checking NaN in all df
df.isnull().values.any()
# get column-slices
@spepechen
spepechen / eda.py
Created January 5, 2016 22:23
first step of data analysis
%matplotlib inline
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
df = pd.read_csv("sample.csv")
plt.style.use('spe')
@spepechen
spepechen / ploting-matplotlib.py
Last active April 10, 2016 01:50
useful #matplotlib tips
######### setting fig size
# Get current size
fig_size = plt.rcParams["figure.figsize"]
# Prints: [8.0, 5.0]
print "Current size:", fig_size
# Set new figure width to 8 and height to 5
fig_size[0] = 8
fig_size[1] = 5