Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Peter Rob, Carlos Coronel

6th International Edition

061921323X, 978-0619213237

More Books

Students also viewed these Databases questions