如何用单个值替换数据框列的值?

时间:2017-02-21 10:42:46

标签: python pandas dataframe

我有一个数据框列,其字符串值如下:

type      caught    bowled       hit

我想将完整列更改为1.我尝试了以下代码:

ct['dismissal_kind']=1

但它没有用。如何将值更改为1?

1 个答案:

答案 0 :(得分:1)

试试这个: -

解决方法1: -

pandas.concat([df['type'].dropna(), df['caught'].dropna(),df['bowled'].dropna(),df['hit'].dropna()]).reindex_like(df)

如果您希望该数据成为新的栏栏,只需将结果分配给df['dismissal_kind']

溶液2: -

dataframe["dismissal_kind"] = dataframe["type"].map(str) + dataframe["cought"].map(str)+dataframe["bowled"].map(str)+dataframe["hit"].map(str)