0

I have a pandas Dataframe like as follow:

                   column1         column2
0                     0               0
1                     0               0
2                     0               0
3                     0               0
...                  ...             ...

I would like to change all data in column2 with

a = numpy.zeros([16,16,16])

so the dataframe will look like

                   column1         column2
0                     0           [[[0,0,0,....
1                     0           [[[0,0,0,....
2                     0           [[[0,0,0,....
3                     0           [[[0,0,0,....
...                  ...             ...
theo123490
  • 58
  • 1
  • 6
  • df['col'] = [np.zeros([16,16,16])]*len(df) – nag Jul 10 '19 at 08:18
  • Why would you want to do so in the first place? You might aswell keep the numpy array as such and just index it accordingly as you'd also do with the dataframe – yatu Jul 10 '19 at 08:20

1 Answers1

2

First I think working with lists or array's this way in pandas is not good idea.

But it is possible:

df['column2'] = [a for _ in df.index]
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252
  • 1
    Thank you, I was using my an old data frame that uses that format exactly, changing everything is quite a hassle, so I rather just change using that format. – theo123490 Jul 17 '19 at 01:57