Skip to content

Instantly share code, notes, and snippets.

View ahmedshahriar's full-sized avatar
🏠
Working from home

Ahmed Shahriar Sakib ahmedshahriar

🏠
Working from home
View GitHub Profile
@ahmedshahriar
ahmedshahriar / detect_missing_values.py
Last active November 16, 2021 19:45
A simple function to check for missing values and percentage
# data - pandas dataframe
def missing_value_describe(data):
# check missing values in the data
total = data.isna().sum().sort_values(ascending=False)
missing_value_pct_stats = (data.isnull().sum() / len(data)*100)
missing_value_col_count = sum(missing_value_pct_stats > 0)
# missing_value_stats = missing_value_pct_stats.sort_values(ascending=False)[:missing_value_col_count]
missing_data = pd.concat([total, missing_value_pct_stats], axis=1, keys=['Total', 'Percent'])
Icons
Avater pack
1. https://www.flaticon.com/packs/avatars-93
@ahmedshahriar
ahmedshahriar / mongodecimal_field.py
Created March 9, 2021 22:03
MongoDecimalField to work with mongdb decimal field using djongo
"""
MongoDecimalField to work with mongdb decimal field using djongo
"""
from bson.decimal128 import Decimal128
from djongo.models import DecimalField
# https://github.com/nesdis/djongo/issues/82
# https://github.com/nesdis/djongo/issues/378
@ahmedshahriar
ahmedshahriar / database.ini
Last active April 12, 2021 09:52
Postgres initialization with Python. contains two script , 1. Postgres db config , 2. db connector
[postgresql]
host=localhost
database=my_db
user=postgres
password=postgres
@ahmedshahriar
ahmedshahriar / concurrent_test.py
Last active July 9, 2021 00:11
This python script will map a list (length 10 for 10 executor) and execute 10 concurrent processes using concurrent module
import concurrent.futures
def test(li):
# print('hello world')
if li:
print('hello world', li)
def run_all(li):
@ahmedshahriar
ahmedshahriar / merge_csv_identical_cols.py
Created May 7, 2021 17:44
Merge multiple CSV files with identical columns
import pandas as pd
import glob
path = r'C:\DRO\DCL_rawdata_files' # use your path
all_files = glob.glob(path + "/*.csv")
li = []
for filename in all_files:
df = pd.read_csv(filename, index_col=None, header=0) # to keep a single header
@ahmedshahriar
ahmedshahriar / hyperparameter_tuning_gridsearchCV_randomsearchCV.py
Created September 7, 2021 14:04
A simple function which takes model and parameter space as input and to tune the hyperparameters of a model using Grid Search or Random Search method selected
from sklearn.model_selection import GridSearchCV, RandomizedSearchCV, StratifiedKFold
from sklearn.metrics import accuracy_score
# configure the cross-validation procedure
kf = StratifiedKFold(n_splits = 10 , shuffle = True , random_state = 42)
def tune_hyperparameter(search_method, estimator, search_space):
# enumerate splits
outer_results = list()
@ahmedshahriar
ahmedshahriar / icon-scholar.html
Last active September 21, 2021 16:55 — forked from epignatelli/icon-scholar.html
Fontawesome icon for Google Scholar
// google-scholar.svg
<svg height="2500" width="2500" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
<g fill="none" fill-rule="evenodd"><path d="M256 411.12L0 202.667 256 0z" fill="#4285f4"/>
<path d="M256 411.12l256-208.453L256 0z" fill="#356ac3"/>
<circle cx="256" cy="362.667" fill="#a0c3ff" r="149.333"/>
<path d="M121.037 298.667c23.968-50.453 75.392-85.334 134.963-85.334s110.995 34.881 134.963 85.334H121.037z" fill="#76a7fa"/>
</g>
</svg>
// style.css
@ahmedshahriar
ahmedshahriar / 4956984.py
Created February 19, 2022 11:47 — forked from miku/4956984.py
How do you split a csv file into evenly sized chunks in Python?
#!/usr/bin/env python
# import csv
# reader = csv.reader(open('4956984.csv', 'rb'))
def gen_chunks(reader, chunksize=100):
"""
Chunk generator. Take a CSV `reader` and yield
`chunksize` sized slices.
"""