8-Bit Borges
8-Bit Borges

Reputation: 10033

Pandas - apply multiplication factor to column values

I have I dataframe:

cases_df = pd.DataFrame(list(cases.items()),
                   columns=['day', 'cases'])

where case.items() is structured like so:

([('2020-04-04T00:00:00Z', 10360), ('2020-04-05T00:00:00Z', 11130), ('2020-04- 06T00:00:00Z', 12161)])

how can I apply a multiplication factor, say 'x', only to 'cases' column?

example x = 100:

'2020-04-04T00:00:00Z'  1036000
'2020-04-05T00:00:00Z'  1113000
'2020-04- 06T00:00:00Z' 1216100

Upvotes: 0

Views: 694

Answers (3)

Daniel Geffen
Daniel Geffen

Reputation: 1862

This should work:

cases_df['cases'] *= x

Upvotes: 1

BENY
BENY

Reputation: 323276

IIUC

cases_df.cases*=100
cases_df
                     day    cases
0   2020-04-04T00:00:00Z  1036000
1   2020-04-05T00:00:00Z  1113000
2  2020-04- 06T00:00:00Z  1216100

Upvotes: 1

fmarm
fmarm

Reputation: 4284

You can simply do

cases_df['cases']  = x*cases_df['cases']

Upvotes: 0

Related Questions