Feb-09-2020, 05:52 AM
Hi,
I've got some data in a csv file in the following format:
ID Number
a 1
a 2
a 3
a 4
b 5
b 6
b 7
b 8
c 9
c 10
c 11
c 12
I need it in a matrix/tabular format i.e.:
a b c
1 5 9
2 6 10
3 7 11
4 8 12
I can read the csv into a dataframe, etc. I'm struggling to convert the array into the matrix using numpy and/or panda array manipulations.
I can isolate a specific set of data using something like data.Number[data.ID='a']. I can also get the unique ID's data.ID.unique.
I was thinking of using a for uniqueID in data.ID.unique loop to then append the data to a new array in amatrix format.
Any sugestions on how to append the arrays and allocate headers to form the matrix?
Cheers,
OM
I've got some data in a csv file in the following format:
ID Number
a 1
a 2
a 3
a 4
b 5
b 6
b 7
b 8
c 9
c 10
c 11
c 12
I need it in a matrix/tabular format i.e.:
a b c
1 5 9
2 6 10
3 7 11
4 8 12
I can read the csv into a dataframe, etc. I'm struggling to convert the array into the matrix using numpy and/or panda array manipulations.
I can isolate a specific set of data using something like data.Number[data.ID='a']. I can also get the unique ID's data.ID.unique.
I was thinking of using a for uniqueID in data.ID.unique loop to then append the data to a new array in amatrix format.
Any sugestions on how to append the arrays and allocate headers to form the matrix?
Cheers,
OM