0

I have multiple files to be imported which would each contain a set of data:

a1,10
a2,20
a3,20
b1,100
b2,100
a1,100
a2,10
a3,100
b1,30
b2,100

I'm trying to get them into the format:

a1,10,100,...
a2,20,10,...
a3,20,100,...
b1,100,30,...
b2,100,100,...

I will have 100s of files which I'd like to concatenate lines together. My first thought was to create an array, cycle through each file to capture the relevant percentage into the array for each ID and then output each array at the end and in PHP I could do this fairly easily with a

if(!isset($$ArrayName)) {
    $$ArrayName = array();
}
array_push($$ArrayName, $Plant);  

With python I can't find an obvious equivalent any suggestions

Thanks Richard

Richard
  • 89
  • 5
  • I would suggest taking a look at the [pandas](https://pandas.pydata.org) library... – Matteo Zanoni Oct 21 '22 at 12:51
  • Even in PHP, that would be terrible code… – deceze Oct 21 '22 at 12:51
  • `list` is the Python equivalent for PHP `array`. you can use the `list.append` method to add an element to a given list: https://docs.python.org/3/tutorial/datastructures.html#more-on-lists – Tryph Oct 21 '22 at 12:52

0 Answers0