Skip to content

Instantly share code, notes, and snippets.

View egemenzeytinci's full-sized avatar
💻
Work hard play hard

Egemen Zeytinci egemenzeytinci

💻
Work hard play hard
  • Istanbul, Turkey
View GitHub Profile
@egemenzeytinci
egemenzeytinci / iterm2 key mapping
Created October 11, 2018 11:49 — forked from trK54Ylmz/iterm2 key mapping
Iterm2 keyboard shortcuts
Send hex code
⌥←Delete = 0x17 - delete word
^←Delete = 0x15 - delete line
Send escape sequence
⌥← = Esc + b = move to left
⌥→ = Esc + f = move to right
@egemenzeytinci
egemenzeytinci / draw_pie.py
Last active September 25, 2021 16:17
Matplotlib pie chart by n values or threshold
import matplotlib.pyplot as plt
import pandas as pd
def pie_by_first_n(df, label_col, size_col, other_name='others', n=5):
df_sum = df.groupby(label_col)[size_col].sum().reset_index()
df_sum = df_sum.sort_values(by=size_col, ascending=False)
df2 = df_sum[:n].copy()
@egemenzeytinci
egemenzeytinci / pandas_options.py
Last active June 14, 2019 08:24
Set some options in pandas
import pandas as pd
# display full columns
pd.set_option('display.max_columns', None)
# display full rows
pd.set_option('display.max_rows', None)
# non-truncated col values
pd.set_option('display.max_colwidth', -1)
@egemenzeytinci
egemenzeytinci / api_connection.py
Created November 20, 2019 20:19
Connection with service accounts for Google APIs with "ImportError: cannot import name SignedJwtAssertionCredentials" error
from oauth2client.service_account import ServiceAccountCredentials
import httplib2
import os
SCOPE = 'API_SCOPE'
ACCOUNT = 'SERVICE_ACCOUNT'
KEY = 'KEY_PATH'
def initialize():
@egemenzeytinci
egemenzeytinci / preprocessing.py
Last active November 26, 2019 21:28
Preprocessing steps in python
from nltk.corpus import stopwords
from stemming.porter2 import stem
import nltk
import re
import string
nltk.download('punkt')
nltk.download('stopwords')
default_stopwords = stopwords.words('english')
@egemenzeytinci
egemenzeytinci / feature_importance.py
Created December 15, 2019 09:58
Feature importances in python
from rfpimp import permutation_importances
from sklearn.base import clone
from sklearn.ensemble import RandomForestRegressor
from sklearn.metrics import r2_score
from sklearn.model_selection import train_test_split
import pandas as pd
def imp_df(column_names, importances):
data = {
@egemenzeytinci
egemenzeytinci / tweet_dumper.py
Created December 20, 2019 11:08 — forked from yanofsky/LICENSE
A script to download all of a user's tweets into a csv
#!/usr/bin/env python
# encoding: utf-8
import tweepy #https://github.com/tweepy/tweepy
import csv
#Twitter API credentials
consumer_key = ""
consumer_secret = ""
access_key = ""
@egemenzeytinci
egemenzeytinci / iqr.py
Created December 25, 2019 15:11
Outlier detection with iqr
cleaned = df.copy()
columns = [
'lead_time',
'stays_in_weekend_nights',
'stays_in_week_nights',
'adults',
'children',
'babies',
'adr',
def select(X):
selects = []
selector = SelectKBest(chi2, k='all').fit(X, y)
scores = selector.scores_
q3 = np.quantile(scores, 0.75)
q1 = np.quantile(scores, 0.25)
iqr = q3 - q1
threshold = q3 + 1.5 * iqr
def compare():
for is_le in [True, False]:
method = 'label encoder'
if is_le:
selected = df_le[selects_le + ['is_canceled']]
else:
selected = df_hot[selects_hot + ['is_canceled']]
method = 'dummy variables'