Assigning values from grouping in pandas
<p>I have a question that I cant resolve. Lets see if you can help me.</p>

<p>I have this df:</p>

<pre><code>df = pd.DataFrame(np.random.randint(0,3,size=(7, 4)),columns=['ONE', 'TWO', 'NAMES', 'FOUR'],index = fechas)
df['NAMES'] = ['Peter','Jon',' Mary','Mary','Peter','Peter','Mary']
</code></pre>

<p>Suppose that I want to group by names in col names and once I've done this I want to assign the values of col 1 to col 2 by the groups recently done, following the criteria  that I have to assign the value of the element in col 1 to the whole  group by name that has the first 0 in col 4 </p>

<p>This is what I got</p>

<pre><code>            ONE  TWO  NAMES  FOUR
1970-01-01    0    0  Peter     0
1970-01-02    2    1    Jon     0
1970-01-03    1    0   Mary     0
1970-01-04    1    1   Mary     0
1970-01-05    0    2  Peter     1
1970-01-06    2    2  Peter     0
1970-01-07    0    0   Mary     1
</code></pre>

<p>And I need something like this:</p>

<pre><code>            ONE  TWO  NAMES  FOUR
1970-01-01    0    0  Peter     0
1970-01-02    2    1    Jon     0
1970-01-03    1    1   Mary     0
1970-01-04    1    1   Mary     0
1970-01-05    0    0  Peter     1
1970-01-06    2    0  Peter     0
1970-01-07    0    1   Mary     1
</code></pre>

<p>I hope it is all well explained. 
Thank you</p>