I have a PySpark dataframe where I want to filter out rows that exist in both english and spanish, some mock data:
test_data = [('1', '2022-09-01' , '07:30:29' , '[tech, fx]' , 'YouTube' , 'english' ,'some text here'),
('2', '2022-09-01' , '07:30:29' , '[finance, fx]' , 'YouTube' , 'english' ,'some text here'),
('3', '2022-09-02' , '06:30:29' , '[tech, banking]' , 'YouTube' , 'english' ,'some text here'),
('4', '2022-09-02' , '07:20:29' , '[tech, banking]' , 'YouTube' , 'spanish' ,'Spanish Text'),
('5', '2022-09-03' , '07:12:55' , '[finance, fx]' , 'YouTube' , 'english' ,'some text here'),
('6', '2022-09-05' , '09:12:55' , '[computer]' , 'Instagram' , 'spanish' ,'Spanish Text'),]
test_data = spark.sparkContext.parallelize(test_data).toDF(['id', 'date', 'time', 'tags', 'source', 'language', 'text'])
+---+----------+--------+---------------+---------+--------+--------------+
| id| date| time| tags| source|language| text|
+---+----------+--------+---------------+---------+--------+--------------+
| 1|2022-09-01|07:30:29| [tech, fx]| YouTube| english|some text here|
| 2|2022-09-01|07:30:29| [finance, fx]| YouTube| english|some text here|
| 3|2022-09-02|06:30:29|[tech, banking]| YouTube| english|some text here|
| 4|2022-09-02|07:20:29|[tech, banking]| YouTube| spanish| Spanish Text|
| 5|2022-09-03|07:12:55| [finance, fx]| YouTube| english|some text here|
| 6|2022-09-05|09:12:55| [computer]|Instagram| spanish| Spanish Text|
+---+----------+--------+---------------+---------+--------+--------------+
Desired logic: Remove row in spanish IF there is another row +-2 hours from that row with the exact same date, tags and source.
I.e., in this example, I would only want to remove row 4.