Skip to content

Instantly share code, notes, and snippets.

@subhsaha
subhsaha / AVG-window-function.scala
Created March 25, 2023 17:32
AVG window function
import org.apache.spark.sql.expressions.Window
import org.apache.spark.sql.functions._
val winsales = spark.table("winsales")
val windowSpec = Window.orderBy(col("dateid"), col("salesid")).rowsBetween(Window.unboundedPreceding, Window.currentRow)
val result = winsales
.select(col("salesid"), col("dateid"), col("sellerid"), col("qty"),
a = [1,2,3,4,5,6,7,8,9,'cat']
print(len(a)*2)
a = [1,2,3,4,5,6,7,8,9,'cat']
print(len(a))
@subhsaha
subhsaha / Length of National Highways.py
Created November 17, 2018 13:28
Length of National Highways
import pandas as pd
df = pd.DataFrame(pd.read_csv("Lengthofnationalhighway.csv"))
df = df.melt(id_vars=['Loc'])
df.to_csv("Lengthofnationalhighwaytwo.csv",index = False)
import pandas as pd
marks = {'student x':[10,20,30,40,50,60],
'student Y':[80,90,100,10,20,30],
'student Z':[40,50,60,70,80,90]}
df = pd.DataFrame(marks) #creating DataFrame from dictionary
print(df) #printing before renameing
df.rename(columns={'student x':'Week_Number'})
@subhsaha
subhsaha / Dictionary to DataFrame.py
Last active October 13, 2018 16:31
Dictionary to DataFrame
import pandas as pd
marks = {'student x':[10,20,30,40,50,60],
'student Y':[80,90,100,10,20,30],
'student Z':[40,50,60,70,80,90]}
print(marks) #printing python dictionary directly
pd.DataFrame(marks) #converting it into DataFrame
@subhsaha
subhsaha / list.py
Created October 7, 2018 13:04
List
k = [2,4,4,1,1,7,9,'bela']
def x():
print("Hello Hey ! ")
x()
x()