Skip to content

Instantly share code, notes, and snippets.

View hoeztutar's full-sized avatar

Hasan "Hasi" Öztutar hoeztutar

View GitHub Profile
@hoeztutar
hoeztutar / read.py
Last active October 8, 2021 13:45
Read json column with nans #pandas #json
import pandas as pd
import json
#first map the text json with json loads, then turn this series in to dict then read df from dict
#if there were no nans you could pass orient='column'
df_context = pd.DataFrame.from_dict(df.context.map(lambda x: json.loads(x.replace('""', '"')), na_action='ignore').to_dict()).transpose()
@hoeztutar
hoeztutar / custom_sort.py
Last active October 7, 2021 07:52
Custom sort Pandas dataframes #pandas #sort
#Make a list of your sort e.g.
cat_list = [ 'Stockout', 'Sell-Out', 'Inventory', 'Run Rate', 'Dead Inv', 'Dead Inv QTY']
#Get the column you want to sort and turn it into a Categorical
df['Category'] = pd.Categorical(df['Category'], cat_list, ordered=True)
#Then Sort
df.sort_values(['Account', 'Category'], ascending=[False, True]) #Sorts Account alphabetically and Category as above
@hoeztutar
hoeztutar / fetc.js
Created September 22, 2021 14:42
Get text of a promise #js
SOMESPONSE.then(response=>response.json())
.then(data=>{ console.log(data); })
@hoeztutar
hoeztutar / notes.md
Last active September 20, 2021 15:10
User Defined Tables/Parameters

User Defined Tables

@hoeztutar
hoeztutar / notes.md
Created September 16, 2021 09:12
Everything about glob

‎‎​

@hoeztutar
hoeztutar / cols_info.py
Created April 28, 2021 09:32
[Dataframe Info] prints the information about columns of a dataframe #pandas #column
#%%
for col in df.columns:
print("="*30,col,"="*30)
print("Max length for {} is {}".format(col, df[col].str.len().max()))
print("Number of unique items {}".format(df[col].nunique()))
if len(df[col].unique()) > 20:
print(np.random.choice(df[col].unique(), 20))
else:
print(df[col].unique())
print("\n")
@hoeztutar
hoeztutar / clean_statusbar.vbs
Created April 19, 2021 06:52
[Empty Statusbar before save] Cleans the Excel Status Bar just before saving the document. #excel #vba
''' This code should be placed in ThisWorkbook
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Application.StatusBar = False
End Sub
@hoeztutar
hoeztutar / message_box.py
Created March 19, 2021 07:44
Show message box on Excel instance
import win32api
import xlwings as xw
wb = xw.books.active
win32api.MessageBox(wb.app.hwnd, "Data transfered successfully", "Success")
import win32api
import xlwings as xw
wb = xw.books.active
win32api.MessageBox(wb.app.hwnd, "Data transfered successfully", "Success")
@hoeztutar
hoeztutar / log.vbs
Created March 9, 2021 15:01
[Write to Windows Application Log] Writes a message to application eventlog #vba #outlook
'Source https://stackoverflow.com/questions/50587769/how-to-write-start-of-excel-reporting-into-eventlog
Public Enum EventType
xlLogSuccess = 0
xlLogError = 1
xlLogWarning = 2
xlLogInformation = 4
xlLogAudit_Success = 8
xlLogAudit_Failure = 16
End Enum