I have a DataFrame and want to check that a record with the latest date has a certain value. For example, for the below DF I need to check the records with Id 'B30' and get the record with the metric_1 == 0.25.
original_metrics_df = self.spark.createDataFrame(
[('A10', -0.35, '2020-01-04'),
('A20', -0.20, '2017-05-01'),
('B30', 0.59, '2018-02-08'),
('B30', 0.25, '2019-05-01')
],
['id', 'metric_1', 'transaction_date']
)
First I did the filtering to retain only records with Id B30:
filtered_metrics_df = original_metrics_df.select('id','metric_1').filter(F.col('metric_1') == 'B30')
How should I apply filtering further to get only a metric_1 value of this record ('B30', 0.25, '2019-05-01')?