I have three numeric tables with different row number, for an example:
tableA |
---|
1 |
8 |
tableB |
---|
10 |
23 |
15 |
80 |
tableC |
---|
500 |
200 |
180 |
And I want to find out something like: A-B C < 200
so the answer is
answer |
---|
1,10,180 |
1,15,180 |
8,10,180 |
Is there any ways to do this?
pandas.DataFrame.query
and numpy.where
seems only work on single table
CodePudding user response:
First use cross join, so possible filter one final DataFrame
:
df = df1.merge(df2, how='cross').merge(df3, how='cross').query("tableA-tableB tableC < 200")
print (df)
tableA tableB tableC
1 1 10 200
2 1 10 180
4 1 23 200
5 1 23 180
7 1 15 200
8 1 15 180
10 1 80 200
11 1 80 180
13 8 10 200
14 8 10 180
16 8 23 200
17 8 23 180
19 8 15 200
20 8 15 180
22 8 80 200
23 8 80 180