Skip to content Skip to sidebar Skip to footer

How To Multiply Each Value In DataFrame Series In Incremental Order Using Pandas

My dataset df looks like this: time Open 2017-01-01 00:00:00 5.2475 2017-01-01 01:00:00 5.2180 2017-01-01 02:00:00 5.2128 ...., .... 2017-12-31 2

Solution 1:

Maybe?

df['Open'] *= (np.arange(len(df)) % 10) + 1

Solution 2:

You can use index of the data frame, if its not pandas generated index , create one and try the code like below

import pandas_datareader as pdr
import pandas as pd
##Connecting to yaoo and getting the stock prices
msft_data=pdr.get_data_yahoo('MSFT','2019-06-18').reset_index()
msft_data['num']= (msft_data.index%10)+1
msft_data['new_high'] = (msft_data.High * msft_data.num)
msft_data

Post a Comment for "How To Multiply Each Value In DataFrame Series In Incremental Order Using Pandas"