简体   繁体   English

用数组更改列中的所有pandas数据框单元格

[英]change all pandas dataframe cell in a column with an array

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 我想改变这一切数据column2

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,....
...                  ...             ...

First I think working with list s or array 's this way in pandas is not good idea . 首先,我认为在熊猫中以这种方式使用listarray并不是一个好主意

But it is possible: 但是有可能:

df['column2'] = [a for _ in df.index]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM