This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
from sqlalchemy import create_engine | |
from sqlalchemy.engine import URL | |
from concurrent.futures import ThreadPoolExecutor | |
# Sample DataFrame | |
data = { | |
'col1': range(100), | |
'col2': range(100, 200) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = [ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(" ") ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import javalang as jl | |
tree = jl.parse.parse(content) | |
def json_ast_encoder(o): | |
if type(o) is set and len(o) == 0: | |
return [] | |
if hasattr(o, "__dict__"): | |
return o.__dict__ | |
return "" | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
Coalesce( | |
try(date_parse(multi_date_format, '%Y-%m-%d %H:%i:%s')), | |
try(date_parse(multi_date_format, '%Y/%m/%d %H:%i:%s')), | |
try(date_parse(multi_date_format, '%Y/%m/%d')), | |
try(date_parse(multi_date_format, '%d %M %Y')), | |
try(date_parse(multi_date_format, '%d %M %Y %H:%i:%s')), | |
try(date_parse(multi_date_format, '%d/%m/%Y %H:%i:%s')), | |
try(date_parse(multi_date_format, '%d-%m-%Y %H:%i:%s')) | |
) as DateConvertedToTimestamp, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT * | |
FROM | |
( | |
SELECT '2021-01-15 13:01:01' AS multi_date_format | |
UNION ALL | |
SELECT '2021/01/15 13:01:02' | |
UNION ALL | |
SELECT '2021/01/03' | |
UNION ALL | |
SELECT '04 JAN 2021' |
NewerOlder