pivoting for 2 columns of values

I have the following data: structure(list(criteria = c("D_max", "ENT_max", "Q_max", "MDCT_min", "BOD_min", "GF_max", "VOL_min"), Mean_ME_opaco = c(2.31951219512195, 3.59547738693467, 3.88265306122449, 5.68948655256724, 6.3643216080402, 6.55635491606715, 6.7), Mean_ME_Transp = c(0.869565217391304, 10.8641975308642, 2.1264367816092, 1, 3.67901234567901, 3.70967741935484, 2.18840579710145), sd_ME_opaco = c(4.13735558695493, 4.39425771945945, 4.71884778320564, 6.86415183201686, 6.50095388599195, 6.43475495235123, 6.56397890542807), sd_ME_Transp = c(1.78154793465634, 6.37525114489569, 3.09088907846522, 2.09208307535884, 4.75086087065762, 4.41824494780745, 3.46102399977589)), row.names = c(NA, -7L), class… Read More pivoting for 2 columns of values

SQL Pivot – Months as Column headers

I have a SQL written as below: select year(recvd_date), (case when month(recvd_date)=1 then count(distinct(app_id)) else 0 end) as Jan, (case when month(recvd_date)=2 then count(distinct(app_id)) else 0 end) as Feb, (case when month(recvd_date)=3 then count(distinct(app_id)) else 0 end) as Mar, (case when month(recvd_date)=4 then count(distinct(app_id)) else 0 end) as Apr, (case when month(recvd_date)=5 then count(distinct(app_id)) else… Read More SQL Pivot – Months as Column headers

pyspark pivot row without aggrefation

I have Pyspark Dataframe named df as below, I need to pivot the data based on ProducingMonth and classification column and need to produce the following output I am using the following pyspark code pivotDF = df.groupBy("WELL_ID","CLASSIFICATION").pivot("CLASSIFICATION") while I am displaying the data I am getting error "’GroupedData’ object has no attribute ‘display’" >Solution :… Read More pyspark pivot row without aggrefation

Pandas convert mutil-row-column dataframe to single-row multi-column dataframe

My dataframe is given below: code: df = Car measurements Before After amb_temp 30.268212 26.627491 engine_temp 41.812730 39.254255 engine_eff 15.963645 16.607557 avg_mile 0.700160 0.733307 cor_mile 0.761483 0.787538 Expected output: modified_df = index amb_temp_Before amb_temp_after engine_temp_Before engine_temp_after … 0 30.268212 26.627491 41.812730 39.254255 … Present output: print(df.pivot(columns=’index’,value=[‘Before’,’After’])) amb_temp engine_temp amb_temp 0 30.268212 NaN NaN NaN NaN… Read More Pandas convert mutil-row-column dataframe to single-row multi-column dataframe

pivot table in pandas with a subtraction function on all possible combinations

I have a dataframe that looks something like Strike. Strike2 Price 15000. 15000. 100 15100. 15100. 150 15200. 15200. 170 I want to create a matrix like df such that the output looks like Strike. 15000. 15100. 15200. 15000. 0. 50. 120 15100. -50 0. 20 15200. -170. -20. 0 Its essentially looking to compute… Read More pivot table in pandas with a subtraction function on all possible combinations