Here is the sample numpy datasource
col row1 row2 row3 row4 columns
[[( 11.2, '689', '197', 'value_2', 0, 1)]
[( 56.4, '689', '197', 'value_3', 0, 1)]
[( 195.7, '689', '197', 'value_2', 0, 2)]
[( 565.2, '689', '197', 'value_3', 0, 2)]
[( 227.6, '689', '197', 'value_2', 0, 3)]
[( 1347.6, '689', '197', 'value_2', 0, 3)]
[( 613.5, '689', '196', 'value_2', 0, 1)]
[(139. , '689', '196', 'value_3', 0, 1)]
[( 6011. , '689', '196', 'value_2', 0, 2)]
[(103. , '689', '196', 'value_3', 0, 2)]
[( 6860. , '689', '196', 'value_2', 0, 3)]
[(1302. , '689', '196', 'value_3', 0, 3)]
[( 1787.9, '622', '197', 'value_2', 0, 1)]
[( 632.5, '622', '197', 'value_3', 0, 1)]
[( 178.8, '622', '197', 'value_2', 0, 2)]
[( 6360.5, '622', '197', 'value_3', 0, 2)]
[( 228. , '622', '196', 'value_2', 0, 1)]
[(672. , '622', '196', 'value_3', 0, 2)]
]
So from this expected output should be
1 2 3
row1 row2 row3 row4
689 197 value_2 0 11.2 195.7 227.6
689 197 value_3 0 56.4 565 1347
689 196 value_2 0 613.5 6011 6860
689 196 value_3 0 139 103 1302
622 197 value_2 0 1787 178
622 197 value_3 0 632 6360
Above 1 2 3 columns are getting from one column in numpy array, that is rank
From the data given, the row1 will always be 1 but it has multiple row2, row3 and row4. For every data in row1 should find equivalent rows and populate as mentioned in the output.
I have tried the below code, but unable to get the (1, 2, 3) column values properly, as it is in different place I couldn't take and write in numpy array.
new_temp_arr = 'actual_data_given'
m = 1
row_list = ['row1', 'row2', 'row3', 'row4']
# Column list taken from the array based on rank column
column_list = [1, 2, 3]
sample_list = []
for value in new_temp_arr:
for new_value in new_temp_arr:
if m >= len(new_temp_arr):
break
new_value = new_temp_arr[m]
# Checking all the values for the rows matches with one another
condition = [value[row] == new_value[row] for row in row_list]
if all(condition):
# Looping through all the column list and getting the float value
# I'm stuck here, how to store the values with properly matched data
for per in column_list:
if new_value['rank'] == [per]:
float_value = new_value['float_value']
sample_list.append(new_value)
m += 1
[]and()suggest it is a structured array, but you haven't provided either shape or dtype. But it could be object dtype, or simply lists of tuples. I don't thinknumpywill help here. For grouping operations I like to usedict, or evencollections.defaultdict.row#values before hand?