I am trying to join a fragment of a dataframe with another one. The structure of the dataframe to join is simplified below:

```
left:
ID    f1   TIME
1     10     1
3     10     1
7     10     1
9     10     2
2     10     2
1     10     2
3     10     2

right:
ID    f2    f3
1      0    11
7      9    11

```

I need to select the left dataset by time, and I need to attached the right one, the result I would like to have is the following:

```
left:
ID    f1   TIME  f2     f3
1     10     1    0     11
3     10     1  nan    nan
7     10     1    9     11
9     10     2  nan    nan
2     10     2  nan    nan
1     10     2  nan    nan
3     10     2  nan    nan

```

Currently I am usually joining dataframes in this way:

```
left = left.join(right.set_index('ID'), on='ID')

```

In this case I am using:

```
left[left.TIME == 1] = left[left.TIME == 1].join(right.set_index('ID'), on='ID')

```

I have also tried with merge, but the result is the left dataframe without any of the other columns.
Finally the structure of my script need to do this for every unique TIME in the dataframe, thus:

```
 for t in numpy.unique(left.TIME):
     #do join on the fragment left.TIME == t

```

If I save the returned value from the join function in a new dataframe everything works fine, but trying to add the value at the left dataframe does not work.

EDIT: The IDs of the left dataset can be present multiple times, but not inside the same TIME value.