How to summarise multiple arrays from one df row into one array?

Question:

How do I "extract" a row from a dataframe containing multiple arrays and transfer it into a single array?

data = numpy.array([([6,5,6], [2,6,3], [3,4,5]), ([0,9,4], [7,6,5], [8,2,4]), (1,3,5)])
df = pd.DataFrame(data)
print(df)

target1 = [6,5,6,2,6,3,3,4,5]
target2 = [0,9,4,7,6,5,8,2,4]

print(target, target2)
Asked By: EmKau

||

Answers:

  1. Extract the row using whichever method you prefer and save it as a list
  2. Use any of these methods to flatten your list
row = list(df.loc[0])
target = [val for val in sublist for sublist in row]
Answered By: supersquires
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.