Skip to content

Instantly share code, notes, and snippets.

View Vuong-Chu's full-sized avatar
🐳
Check your work a few times before submit.

Vuong Chu Vuong-Chu

🐳
Check your work a few times before submit.
View GitHub Profile
@Vuong-Chu
Vuong-Chu / Copy files.py
Created October 21, 2023 21:46
Copy multiple files from sub-folders
'''
This file is used to loop through sub-directories
and copy multiple files with a specific filename,
then rename them in a new folder.
'''
import os, shutil, re
def main():
src = "/media/Folder From"
@Vuong-Chu
Vuong-Chu / Process_outliers.py
Last active August 31, 2023 18:28
This function is to remove outliers in columns of a dataframe and ignore missing values that may be processed in following steps.
# Define function to detect outliers for numerical variables
import pandas as pd
def clean_outliers(data, types = "IQR", threshold = 3.0):
'''
This function will cleanse outliers only
and leave missing values alone.
Parameters:
data (DataFrame): Raw data that need to detect and clean the outliers.
@Vuong-Chu
Vuong-Chu / multi_col_label_encoder.py
Last active August 30, 2023 16:14
Multiple Columns Label Encoders
import pandas as pd
from sklearn.preprocessing import LabelEncoder
class MultiColumnLabelEncoder:
'''
modified the scripts of Daria Vasyukova
'''
def __init__(self, X):
self.X = X
@Vuong-Chu
Vuong-Chu / lat_long_distance.py
Last active June 4, 2023 10:09
Calculate distance between Latitude/Longitude points. All these formulas are for calculations on the basis of a spherical earth (ignoring ellipsoidal effects) – which is accurate enough for most purposes…
from math import radians, sin, cos, atan2, sqrt, tan, atan
def haversine_distance(long1, lat1, long2, lat2, degrees=False):
'''
The haversine formula determines the great-circle distance
between two points on a sphere given their longitudes and latitudes.
'''
#degrees vs radians
if degrees == True:
long1 = radians(long1)
import math
def Wallis_Pi(n):
'''
Compute the decimals of Pi using the Wallis formula:
'''
return 2*math.prod([4*i**2 / (4*i**2 - 1) for i in range(1, n + 1)])
Wallis_Pi(100_000)