2

I am using Python with Pandas. How can I multiply a column by 1000 given another column has a certain string?

rafaelc
  • 57,686
  • 15
  • 58
  • 82
KarmaFarma
  • 43
  • 1
  • 1
  • 3
  • Possible duplicate of [Pandas conditional creation of a series/dataframe column](https://stackoverflow.com/questions/19913659/pandas-conditional-creation-of-a-series-dataframe-column) – rafaelc Feb 08 '19 at 16:28

1 Answers1

14

This should do it.

df['columnname'] = np.where(df['othercolumn'] == 'CertainString',
                                           df['columnname'] * 1000,
                                           df['columnname'])
Nathan Hellinga
  • 355
  • 3
  • 6