Question: Convert SAS program to python ( Without Pandas ) : DATA test; INPUT prenom :$ 9 . ; CARDS; Mathilde Fr d ric Subira Fr

Convert SAS program to python (Without Pandas) :
DATA test;
INPUT prenom :$9.;
CARDS;
Mathilde
Frdric
Subira
Frdric
Subira
Subira
;
PROC SORT DATA=test;
BY prenom;
RUN;
DATA test2;
SET TEST;
BY prenom;
x1=first.prenom;
x2=last.prenom;
RUN;
Results :
Obs. prenom x1 x2
1 Frdric 10
2 Frdric 01
3 Mathilde 11
4 Subira 10
5 Subira 00
6 Subira 01
This is what I have already been able to do but it is not the desired result :
df_test= spark.createDataFrame(["Mathilde","Frdric","Subira","Frdric","Subira","Subira"], "string").toDF("prnom")
from pyspark.sql import functions as F, Window as W
w = W.partitionBy('prnom').orderBy("prnom")
df = df_test.withColumn('X', F.row_number().over(w))

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!