Search code examples
pythonpandasdataframenumpystock

How to copy a value to another cells using weeknumber in padas python dataframe?


Please refer below image. I am trying to create a new column (i.e., Expected_Open) in Pandas dataframe. This columns will fetch Open value for each Monday of a give week. Thanks for your help.

enter image description here

following if condition only returns data in row = "Monday", but I am not sure how to copy it to other weekdays: if (x['Weekday'] == "Monday") : return x['open']


Solution

  • df['Expected_Open'] = df['Weeknumber'].map(dict(df.loc[df['Weekday'] == 'Monday', ['Weeknumber', 'Open']].to_numpy()))