1

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?

3 Answers 3

5

You should be able to simply:

df.loc[:, 'Foldchange'] = 2
Sign up to request clarification or add additional context in comments.

Comments

4

Similar to Stefan, you can also do

df['Foldchange']=2.0

Comments

-2

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.

2 Comments

Since the question is, "How can I do that conveniently in Pandas?" and your response starts with, "I don't know pandas" - How about electing not to post. At this point, removing this response might be helpful since it doesn't add value to the conversation.
The link provided is to another SO which answered the question as initially asked with several examples and two strong answers. I do not need Pandas experience to recognize a duplicate/similar question which could answer the posters question and avoid people re-explaining something. If anything, the constructive criticism you point out is that admitting no experience with the product does not inform the usefulness of the link and should have been omitted.

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.