Skip to content

Instantly share code, notes, and snippets.

View thangarajan8's full-sized avatar
💭
Learning to How to Learn

itsthanga thangarajan8

💭
Learning to How to Learn
View GitHub Profile
import pandas as pd
import numpy as np
import json
f_path = "HomePage.java"
with open(f_path,'r') as f:
content = f.read()
def flattern_json(d):
if len(d) == 0:
return {}
import pandas as pd
import numpy as np
import json
f_path = "ContactsPage.java"
with open(f_path,'r') as f:
content = f.read()
#def flattern_json(d):
# if len(d) == 0:
# return {}
import datetime
# text = "april 23 january 11 2020"
text = "enero 01 diciembre 31 2020"
def multi_date_text(text):
month_dict = {"enero":"january","febrero":"february","marzo":"march","abril":"april",
"mayo":"may","junio":"june","julio":"july","agosto":"august",
"septiembre":"september","octubre":"october","noviembre":"november","diciembre":"december"}
text = [month_dict[i] if i.lower() in month_dict.keys() else i for i in text.split(" ") ]
@thangarajan8
thangarajan8 / gist:68640b9cc0958fc925c68d9777f05f63
Created May 10, 2022 12:22
pandas to spark data frame.py
from pyspark.sql.types import *
# Auxiliar functions
# Pandas Types -> Sparks Types
def equivalent_type(f):
if f == 'datetime64[ns]': return DateType()
elif f == 'int64': return LongType()
elif f == 'int32': return IntegerType()
elif f == 'float64': return FloatType()
else: return StringType()
from pyspark.sql import SparkSession
from pyspark.sql.functions import col, sum as spark_sum, when
# Initialize Spark session
# spark = SparkSession.builder \
# .appName("Sales Analysis") \
# .getOrCreate()
# Sample data
data = [
@thangarajan8
thangarajan8 / date_time_diff.py
Created September 20, 2024 08:03
date_time_diff
from pyspark.sql import SparkSession
from pyspark.sql.functions import col, udf, expr, hour,format_number
from pyspark.sql.types import LongType
import pandas as pd
# Initialize Spark session
spark = SparkSession.builder.appName("DateDifference").getOrCreate()
def exclude_weekends_and_jan1(start_date, end_date):
# Create a date range
@thangarajan8
thangarajan8 / delete.py
Last active July 25, 2025 12:20
to be delete
def clean_amount(value):
# Move trailing minus to the front
value = value.replace('-', '')
is_negative = value.endswith('-') or value.startswith('-')
# Remove thousand separator and convert decimal separator
value = value.replace('.', '').replace(',', '.').replace('-', '')
# Convert to float
try: