0

I have this array:

[[1,2,3],[4,5],[7,8,9]]

I tried to use pandas.to_csv but it gives me

1 2 3
4 5 nan
7 8 9

but I want

1 4 7
2 5 8 
3 nan 9

1 Answers1

0

I would first ensure all rows have the same length:

a = [[], [1], [1,2], [1,2,3]]
max_row_length = max([len(r) for r in a])
a = [r + [None]*(max_row_length - len(r)) for r in a]

and then I would use numpy:

np.array(a).T
SheepPerplexed
  • 1,132
  • 8
  • 20