neversaint
neversaint

Reputation: 64034

How to replace values in column for every rows with same values in Pandas

I have a DataFrame that looks like this:

In [10]: import pandas as pd
In [11]: df = pd.read_table("http://dpaste.com/2M75260.txt",sep=",")
In [12]: df.head(n=3L)
Out[12]:
             ID    Genes  Foldchange
0    1415670_at     Copg       0.989
1    1415673_at     Psph       1.004
2  1415674_a_at  Trappc4       1.000

In actuality there are around 40K rows. What I want to do is to change the all the values in Foldchange with same value 2.

So that it will looks like:

ID            Genes  Foldchange
1415670_at     Copg       2.000
1415673_at     Psph       2.000
1415674_a_at  Trappc4     2.000
.... etc...

How can I do that conveniently in Pandas?

Upvotes: 1

Views: 4206

Answers (3)

NinjaGaiden
NinjaGaiden

Reputation: 3146

Similar to Stefan, you can also do

df['Foldchange']=2.0

Upvotes: 4

A Small Shell Script
A Small Shell Script

Reputation: 620

I don't know pandas, but a quick search: Python pandas equivalent for replace

Since read_table returns a dataframe, you should be able to do a list comprehension or map() with the result() method.

Upvotes: -2

Stefan
Stefan

Reputation: 42885

You should be able to simply:

df.loc[:, 'Foldchange'] = 2

Upvotes: 5

Related Questions