Reputation: 11
I have a dataframe with 3 columns and 4 row,
import pandas as pd
df_ticker = pd.DataFrame({'Min_val': [22382,37876,46717,62247], 'Max_val': [36901,46716,62045,182727],
'Ticker':['$','$$','$$$','$$$$']})
df_ticker
Sample input:
I want to modify Min value in the dataframe so than at index 1 min_val=max_val(at index 0) + 1.
Output:
Please let me know how I can achieve this.
Upvotes: 0
Views: 40
Reputation: 59529
The shift function works. To keep the Min_val in the first column you can just specify 1:
with the loc
function, otherwise it would set the first row to NaN
df_ticker.loc[1:,'Min_val'] = df_ticker['Max_val'].shift(1) + 1
Upvotes: 1