Update column in one data frame with value of column from another data frame

Hi there

In Python 3.7 , I need some help with the syntax of updating data frame with value from another data frame:

I have a trade and it has 2 rows - one for the start and one for the end

I would like to update the start time in end row.

for example - df_start (start trades) and df_end (end trades) - the column position_id is identical between them (this column is the key for the 2 data frames)

I need the column time in df_end to change like that : df_end[‘time’] = df_start[‘time’]

Thanks for the help :slight_smile:

Hi @flexer .
I would be super helpful for fellow users to understand your problem if you could give some input dataframe and expected output dataframe.

Hi

Here is an example:

df1 = pd.DataFrame({‘position_id’: [‘728441371’, ‘728451946’, ],
‘time’: [‘02/10/2020 15:21:32’, ‘02/10/2020 15:30:04’],
‘profit’:[0,0]})

df2 = pd.DataFrame({‘position_id’: [‘728441371’, ‘728451946’, ],
‘time’: [‘02/10/2020 15:30:42’, ‘02/10/2020 15:30:07’],
‘profit’:[3.32,-7.7]})

result_df = pd.DataFrame({‘position_id’: [‘728441371’, ‘728451946’, ],
‘time’: [‘02/10/2020 15:21:32’, ‘02/10/2020 15:30:04’],
‘profit’:[3.32,-7.7]})

i.e - the result data frame is : take the time in df1 and update the time in df2

There is no difference between the Python data frame and the R data frame.
We will use an inbuilt data frame. Both are used to analyze the dataset.

The syntax of Python df = pd.DataFrame( ) and R df = data.frame( ).