Overview
I have lists of tuples in a pandas series containing a price and associated date in each tuple.
Test data
SeriesDict = {0: [(0.9919, '2002-05-31 21:00:00+00:00'),
(0.9898, '2002-09-30 21:00:00+00:00'),
(0.9905, '2002-10-31 22:00:00+00:00')],
1: [(1.01195, '2002-06-30 21:00:00+00:00'),
(1.013, '2002-10-31 22:00:00+00:00')]}
TestSeries = pd.Series(SeriesDict)
What have I tried?
I can get the max date from the list of tuples as follows:
TestSeries.apply(lambda x: max([y[1] for y in x])).iloc[0]
which returns '2002-10-31 22:00:00+00:00'
. I will later use this to create a new column with max date
for each row in a new dataframe.
How do I now retrieve the price associated with max date
(price is y[0]
from the tuple) using apply or similar?
Desired output is a new column with the price associated with each date i.e. 0.9905
should be returned for this example.