I am trying to move from SAS into Python and I am facing a few challenges. Specifically, I have a dataset with 301 observations with in wide-format and I am trying to reshape it into long-format. The wide-format dataframe looks like below:
And I want to convert it into a long-format that would look like as below:
The SAS code I have used to convert my dataset from wide to long is:
data longformat;
set wideformat;
array arts(*) art1-art10;
array cits(*) cit1-cit10;
if jobtime =. then jobtime = 11;
do year = 1 to dur;
if year = dur then promo=event; else promo=0;
if year ge jobtime then jobpres=prest2; else jobpres=prest1;
art = arts(year);
cit = cits(year);
output;
end;
run;
Does anyone have any idea how to make this kind of conversion into Python?