Question: I have two tables. 'First' table contains 2 ids of 'second' table. v2 and v3 are second table's IDs.

**First**:

```
`id`, `mem`, `v2`, `v3`, `v2_amt`, `v3_amt`
  1, 'test',  1,     2,   '10',     '20'
  2, 'test2', 1,     2,   '10',     ''

```

**Second**:

```
`id`, `name`
  1, 'anna'
  2, 'teena'

```

When I'm joining,

```
SELECT      f.mem, s.name 

FROM        `first` f 

JOIN        second s 
    ON      f.v2 = s.id 
    AND     f.v2_amt !="" 
    AND     (f.v3 = s.id AND f.v3_amt !='') 

WHERE       f.id = '1' 

GROUP BY    s.id

```

* Currenlty it return none.

Is any way to union both tables to achieve output as following..??

```
`mem`, `name`
  test, 'anna'
  test, 'teena'

```

For fetching 2 id of first table.

```
SELECT      f.mem, s.name 

FROM        `first` f 

JOIN        second s 
    ON      f.v2 = s.id 
    AND     f.v2_amt !="" 
    AND     (f.v3 = s.id AND f.v3_amt !='') 

WHERE       f.id = '2' 

GROUP BY    s.id

```

It should return as, seems v3\_amt is empty.

```
`mem`, `name`
  test, 'anna'

```

Answer: 
Use `dict comprehension` with `groupby`:

```
d = {names[i]: x.dropna() for i, x in df.groupby(df[0].isnull().cumsum())}

{'c':      0
0  7.0
1  8.0
2  9.0, 'b':      0
0  4.0
1  5.0
2  6.0, 'a':      0
0  1.0
1  2.0
2  3.0}

```

---

```
print (d['a'])
     0
0  1.0
1  2.0
2  3.0

print (d['b'])
     0
4  4.0
5  5.0
6  6.0

print (d['c'])
      0
8   7.0
9   8.0
10  9.0

```
Here's one way

Originally,

```
In [2109]: df_dict = dict(zip(
                          names,
                          [g.dropna() for _, g in df.groupby(df[0].isnull().cumsum())]
                             ))

```

On edits realized it's identical to another answer.

```
In [2100]: df_dict = {names[i]: g.dropna() for i, g in df.groupby(df[0].isnull().cumsum())}

In [2101]: df_dict['a']
Out[2101]:
     0
0  1.0
1  2.0
2  3.0

In [2102]: df_dict['b']
Out[2102]:
     0
4  4.0
5  5.0
6  6.0

In [2103]: df_dict['c']
Out[2103]:
      0
8   7.0
9   8.0
10  9.0

```