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)
CodePudding user response:
- Extract the row using whichever method you prefer and save it as a list
- Use any of these methods to flatten your list
row = list(df.loc[0])
target = [val for val in sublist for sublist in row]