如何在Pandas中用一个值填充一列? [英] How do I fill a column with one value in Pandas?

查看:1182
本文介绍了如何在Pandas中用一个值填充一列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Pandas DataFrame中有一列连续的数字.

I have a column with consecutive digits in a Pandas DataFrame.

A
1
2
3
4

我想将所有这些值更改为一个简单的字符串,例如"foo",结果是

I would like to change all those values to a simple string, say "foo", resulting in

A
foo
foo
foo
foo

推荐答案

只需选择该列并像往常一样分配:

Just select the column and assign like normal:

In [194]:
df['A'] = 'foo'
df

Out[194]:
     A
0  foo
1  foo
2  foo
3  foo

分配标量值会将所有行设置为相同的标量值

Assigning a scalar value will set all the rows to the same scalar value

这篇关于如何在Pandas中用一个值填充一列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆