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,....
...                  ...             ...
2
  • df['col'] = [np.zeros([16,16,16])]*len(df) Commented Jul 10, 2019 at 8: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 Commented Jul 10, 2019 at 8:20

1 Answer 1

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]
Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.