-1

I need help in manipulating the data

this is the data.

number, CODE
1003286233, DP
1003286233, PU
1003286233, IA
1003286233, RW

I can't find any code... only rows into column.

the output needs to be like this

1003286233 DP,PU,IA,RW

thank you for the help.

Green Cloak Guy
  • 23,793
  • 4
  • 33
  • 53
bevg1
  • 1
  • Can you structure your data more? – Parijat Bhatt Aug 20 '19 at 19:40
  • what did you tried until now – basilisk Aug 20 '19 at 19:43
  • Please take a look at [How to make good pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) and provide a [mcve] with sample input and output, and what you've tried so far absed on your own research – G. Anderson Aug 20 '19 at 19:44
  • i found this, but i can't get it to work https://www.experts-exchange.com/questions/28491431/what-is-the-python-code-to-transpose-rows-of-data-to-columns-separated-by-commas.html – bevg1 Aug 20 '19 at 19:50

1 Answers1

0

Make a dictionary wher evalue is a list. if you have it like in 2d array and you want to notate it short like;

array2d = [
[1003286233, DP],
[1003286233, PU],
[1003286233, IA],
[1003286233, RW]]

then do like:

d = {}

for line in array2d:
 d.setdefault(line[0], []).extend(line[1:])
snamef
  • 195
  • 1
  • 10
  • the last piece of the code is. for item in dataAgg.keys(): print (item,',',dataAgg[item]) i need to write it to a file... i tried different ways but i have no clue to how do it. any help will be greatly appreciated. – bevg1 Dec 18 '20 at 05:33