0

I have 10 dataframes,df1...df10 with 2 columns:

df1

id | 2011_result,

df2

id | 2012_result, ... ...

df3

id| 2018_result

I want to do select some ids with 2011_result values less than a threshold.

 sample_ids=df1['2011_result']<threshold].sample(10)['id'].values 

After this, I need to select the values for other columns from all other data frames for the list.

Something like this:

df2[df2['id'].isin(sample_ids)]['2012_result'] df3[df3['id'].isin(sample_ids)]['2013_result']

Could you please help out?

1 Answer 1

1

Firstly you can filter with:

import pyspark.sql.functions as F

sample_ids=df1.filter(F.col("2011_result") < threshold)

Then you can use left_anti join to filter out df2, df3, etc:

df2 = df2.join(sample_ids.select("id"), on="id", how="left_anti")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.