This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = [1, 2, 3] | |
b = [0, 1, 0] # Arr with Zeros | |
c = np.divide(a, b, | |
out=np.zeros_like(a), where=b!=0) | |
'''Simply replace a and b with your variables''' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plt.legend(bbox_to_anchor=(1.05, 1), loc='upper left') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Number of elements (total colors to generate in short) | |
N = 30 | |
c = ['hsl('+str(h)+',50%'+',50%)' for h in np.linspace(0, 360, N)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import io | |
import requests | |
url="https://raw.githubusercontent.com/cs109/2014_data/master/countries.csv" | |
s=requests.get(url).content | |
c=pd.read_csv(io.StringIO(s.decode('utf-8'))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This can be made SUPER easily in tableau | |
# visit this link | |
https://www.youtube.com/watch?v=08xh-vvSUqg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# THIS IS AGAIN GONNA BE AMAZING! | |
''' | |
Sometimes we have a LOT - means a million lines of data and making the str.get_dummies("|") will | |
cause the Insufficient Memory Error. | |
So instead of just splitting them and making zeros and ones... (well that is good if we want to | |
keep track the word per movies, but if overall - then that is not good practice) | |
''' | |
# NEW THING! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Define a function in which the group will be passed | |
def get_nlargest(group): | |
# That group's group will be created (not complex) | |
group = group.groupby('key2').value_col.sum() | |
return group.nlargest(5) | |
# X Instead of doing this ↓ | |
df.groupby(['key1', 'key2').apply(lamda group: group...) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
series = pd.Series([], dtype= int) | |
for suite in ['H', 'D', 'S', 'C']: | |
for value, number in enumerate(['A'] + list(range(1, 11)) + ['J', 'Q', 'K']): | |
series = series.add(pd.Series({str(number) + suite: value + 1}), fill_value= 0) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Simple and easy | |
df.gropby(df.index // n_rows).mean() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plt.rcParams['axes.spines.left'] = False | |
plt.rcParams['axes.spines.right'] = False | |
plt.rcParams['axes.spines.top'] = False | |
plt.rcParams['axes.spines.bottom'] = False |