Skip to content

Instantly share code, notes, and snippets.

@zinyosrim
zinyosrim / triangle_df.py
Created December 27, 2018 10:01
Random triangle dataframe, lower half zeros
import numpy as np
import pandas as pd
N = 20
rand_matrix = np.asarray([random.randrange(1,11)/10 for _ in range(1, N*N+1) ]).reshape(N,N)
data = np.flip(np.triu(rand_matrix), 1)
df = pd.DataFrame(data, index=pd.date_range(start='2015-01-01', freq='MS', periods=N),\
columns = range(1,N+1))
df[1]=1
@zinyosrim
zinyosrim / ga_number_to_spreadsheet_number.txt
Created September 27, 2018 06:19
Spreadsheet formula to convert Google Analytics report currency format to number, e.g. €57,647.00 -> 57647
=VALUE(REGEXREPLACE(REGEXEXTRACT(C8;"€([0-9]*\,[0-9]+[0-9]+)");",";""))
@zinyosrim
zinyosrim / pandas_pretty_print_full.py
Created September 15, 2018 17:29
Pretty Print all data frame rows and columns
import pprint
def pprint_full(x):
pd.set_option('display.max_rows', len(x))
pd.set_option('display.max_columns', None)
pd.set_option('display.width', 2000)
pd.set_option('display.float_format', '{:20,.2f}'.format)
pd.set_option('display.max_colwidth', -1)
#print(x)
pprint.pprint(x)
pd.reset_option('display.max_rows')
@zinyosrim
zinyosrim / zip_unzip_example.py
Created September 15, 2018 17:16
Example zipping unzipping
seq1 = ['good', 'bad', 'ugly']
seq2 = ['child', 'man', 'woman']
zipped = zip(seq1, seq2)
starzipped = zip(*[seq1, seq2])
for el in starzipped: print(el)
@zinyosrim
zinyosrim / dict_in_column_to_df_column.py
Last active September 15, 2018 18:09
Make dict keys in a DF column a DF column
df = pd.DataFrame({'order_id': ['A', 'B'],
'address': [{'city': "NY", 'latitude': 2.12, 'longitude' : 3.12,'country_code' : "US"},
{'city': "KL", 'latitude': 12.12, 'longitude' : 23.12,'country_code' : "MY"}]},
columns= ['order_id', 'address'])
new_cols = ['city', 'country_code']
for col in new_cols:
df['address_{}'.format(col)] = df['address'].map(lambda x: np.nan if pd.isnull(x) else x[col])
@zinyosrim
zinyosrim / sample_dataframes.py
Last active January 7, 2019 10:06
Couple of Dataframes for Stackoverflow
pd.DataFrame({'order_id': ['A', 'B'],
'items': [[{'item': 1, 'color': 'blue' },
{'item': 2, 'color': 'red' }],
[{'item': 3, 'color': 'green'},
{'item': 2, 'color': 'pink' }]]},
columns= ['order_id', 'items'])
pd.DataFrame({'order_id': ['A', 'A', 'B', 'B'],
'product_id': [1, 2, 3, 2],
'product_color': ['blue', 'red', 'green', 'pink'] },
Komponente Kurzbeschreibung Argumente dafür Kosten
MailChimp Sehr verbreitetes Newsletter-Versand-System Gute Integration mit anderen Systemen. Großer Funktionsumfang Kostenloser Plan verfügbar
MailMunch Shopify App für automatische Pop-up's granulare Einstellmöglichkeiten für Pop-up's Kostenloser Plan verfügbar. Nächste Stufe ab 12$/Monat
Coupon Carrier Shopify App für das Weiterreichen von Gutschein-Codes an Mailchimp Leicht zu bedienen Verbrauchsabhängige Kosten im Cent Bereich pro versendeten Code
Bulk Discounts Shopify App für Gutschein-Codes leichtes Erzeugen einer großen Anzahl von Gutscheinen Kostenloser Plan verfügbar
@zinyosrim
zinyosrim / import_grouped_data.py
Created August 9, 2018 09:44
Import grouped data in a CSV into Pandas and substitute NaNs through real data
import csv
reader = csv.reader(open('products.csv'))
products_list = []
first_of_group = ""
for row in reader:
product_name, feature1, feature2 = row
product_dict = {}
@zinyosrim
zinyosrim / convertCurrencyToNumber.txt
Created February 14, 2018 14:11
Google Spreadsheets formula to convert currency text to number
=value(regexreplace(regexreplace(REGEXREPLACE(B19;"€"; ""); ",";"");"\.";","))
@zinyosrim
zinyosrim / generate_pandas_dataframe_with_random_integers.py
Created November 23, 2017 19:55
Generate Pandas Dataframe with random integers
import pandas as pd
import numpy as np
from random import randint
df = pd.DataFrame(np.random.randint(0,10,size=(10, 3)), columns=list('ABC'), index=range(1,11))