Skip to content

Instantly share code, notes, and snippets.

View pcmasuzzo's full-sized avatar

Paola Masuzzo pcmasuzzo

  • tpvision
  • Ghent, Belgium
View GitHub Profile
@pcmasuzzo
pcmasuzzo / seaborn_snippets.py
Last active December 5, 2020 21:54
Some useful seaborn snippets
# import
import seaborn as sns
import matplotlib.pyplot as plt
# white background in plots
sns.set(style="whitegrid")
# df is a pandas dataframe
# plot by column by variable 'var1', in 3 columns, coloring by variable 'var2'
grid = sns.FacetGrid(df, col='var1', col_wrap=3, hue='var2', size=4, palette='Set2')
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@pcmasuzzo
pcmasuzzo / pandas_snippets.py
Last active August 23, 2017 10:04
Some useful pandas operations on dataframes
# import
import numpy as np
import pandas as pd
# convert a pandas dataframe to numpy excluding a column
data_matrix = np.array(data[data.columns.difference(['col_to_exclude'])], dtype=float)
# add new column to existing dataframe from another array
df = df.assign(new_col=vector.values)