0

I am extracting data from Tableau and generate a CSV file. I need to reshape the CSV file without using pandas library.My 3P policy wont allow to install any other packages. (Default package I am using is csv)

My generate CSV file :

Name,Experience,Measure names,Measure values
Birla,3,State,CA
Birla,3,Audit,Y
Birla,3,WFH,Y
Birla,3,State,MN
Birla,3,Audit,N
Birla,3,WFH,N
Birla,6,State,SC
Birla,6,Audit,Y
Birla,6,WFH,Y
Rosa,5,State,LA
Rosa,5,Audit,N
Rosa,5,WFH,N
Val,8,State,CO
Val,8,Audit,P
Val,8,WFH,N
Brain,12,State,MO
Brain,12,Audit,Y
Brain,12,WFH,N
Brain,12,State,NY
Brain,12,Audit,N
Brain,12,WFH,Y

enter image description here

My expected output should be :

Name,Experience,State,Audit,WFH
Birla,3,CA,Y,Y
Birla,3,MN,N,N
Birla,6,SC,Y,Y
Rosa,5,LA,N,N
Val,8,CO,P,N
Brain,12,MO,Y,N
Brain,12,NY,N,Y

enter image description here

Is that possible using Default csv package? Request your suggestion on this.

Stay cool
  • 11
  • 6
  • This is doable with the standard `csv` module. Also, please use text rather than images. – wkl Aug 04 '22 at 06:29
  • Is your CSV always sorted by *Name* column? Every *Name* has 3 measurements? – Olvin Roght Aug 04 '22 at 06:31
  • @wkl-Could you please tell me steps to do that.I am unable to add that as text..When i tried it show me a picture – Stay cool Aug 04 '22 at 06:36
  • @OlvinRoght-Due to Measurement names and Measurement values,Additional rows were generated,i am tring to avoid that – Stay cool Aug 04 '22 at 06:38
  • @Staycool, once again. Is it guaranteed that all data related to `Birla` will be grouped one by one? Are there only *State*, *Audit* and *WFH* measurements? – Olvin Roght Aug 04 '22 at 06:41
  • No we should not group by birla...If We have same name for another scenario,then we groupby my sceario wont possible right..Name,Experience is duplicated since we have (state,Audit & WFH) came as rows..For you let me add me another scenario with name "birla" – Stay cool Aug 04 '22 at 06:58
  • @Staycool, try [this](https://tio.run/##bVE9b4MwEN35FScmO0JZulRI2dqxGbJ0qRS55AiWwLYOExpV/e30bD5T1QOYe@/dvXe4u6@seXp2NAwl2QaK9ga6cZY8vOjCn1BdkLJ4fyftkZJICzdvbd3O5CvZzn3eR9Q6JOUtzSCzmyv6oE567atAMIJSbVzn9zwylaC4lTmXGXwkMJ2JZTs/0zJIe34Y7Gtt8JCOOiacyzzKKPqFw8a8CG1lRPuYgNGjNRgrJZsUJgOUWXQZTMxZBE3hV/siPaoGg43XL86o0RSYSpkvlsn23P57@Q5n1OTAYx7rmx454B90t7twBNEoJ7bz31C1HSEY7tkGI3PhpuqOK3MOKZduP8tNl2Csn9aQP4xbVrP@aRH3moVM8h/uPr6qcccrYQuyUgT1MPwC). – Olvin Roght Aug 04 '22 at 07:03
  • @Staycool, or [this](https://tio.run/##bVA7b4MwEN75FRaTHVmoj6VCypauWTu0VUTJESwFn@UcJVHV307PNtCkqgewv5e@O3ehFu3jk/PjaDqHnkR9@swaj50wBJ4QjycxMQePvfu4JBYd@IrQzySruwMQe7JsMNQGgZU@N9b1VHBorkTFUXbXaPGWielMKuxplmmRD/yxMByNhXWefCzYNWW0eaj24MU6NC3SQ4ZYFVkLZ5IJTcDgwyAs36KFiDTcWlotQOlYO7Sah5us@moeeafFvVLl0tnjwHFfyzucfFt1kJeCY2/x5zMvyoCtAwt/2NVqb2qS5vWhfI@1TKgSO6lF@L3cTCMs0jRReZO0TBmWsuHQlwjIuDcdKqt/9EX8tWmHv4Jrkp0yuMfxBw) using simple `reader()`. – Olvin Roght Aug 04 '22 at 07:04
  • @OlvinRoght..Let me check.But i can see "Name","Experience" column name was hard code in Program.But it will not gauranteed we had only 2 columns and the name was same....So it will 12-14 columns names including "measure names","measure values".COlumn name "measure names" and "measure values" -column name will be same for all reports. – Stay cool Aug 04 '22 at 07:18
  • Is that possibble to save as same csv file...? – Stay cool Aug 04 '22 at 07:24
  • @Staycool, yes, it's possible, you need to not write modified columns to separate file but save it into a list and reopen file for writing after and write modified data back – Olvin Roght Aug 04 '22 at 08:39
  • @OlvinRoght Thanks a lot it gives the expected result.Let me ad another case...Please take a look at that...in that scenario we cant group by 'name' or ' experience' – Stay cool Aug 04 '22 at 14:32

0 Answers0