title: Pandas: How to get max and min values and write for every row?
body: <p>I have a data like that; </p>
  
  <pre><code>&gt;&gt; df
      A  B  C  
  0   1  5  1  
  1   1  7  1
  2   1  6  1
  3   1  7  1
  4   2  5  1
  5   2  8  1
  6   2  6  1
  7   3  7  1
  8   3  9  1
  9   4  6  1
  10  4  7  1
  11  4  1  1
  </code></pre>
  
  <p>I want to take max and minimum values of the B column depending on the column A(For the each same value of column A, I want to find the min and max in column B) and want to write results on the original table. My code is:</p>
  
  <pre><code>df1 = df.groupby(['A']).B.transform(max)
  df1 = df1.rename(columns={'B':'B_max'})
  df2 = df.groupby.(['A']).B.transform(min)
  df1 = df1.rename(columns={'B':'B_min'})
  df3 = df.join(df1['B_max']).join(df2['B_min'])
  </code></pre>
  
  <p>This is the result. </p>
  
  <pre><code>    A  B  C  B_max  B_min
  0   1  5  1           
  1   1  7  1  7
  2   1  6  1
  3   1  4  1           4
  4   2  5  1
  5   2  8  1  8
  6   2  6  1           6
  7   3  7  1           7
  8   3  9  1  9
  9   4  6  1
  10  4  7  1  7
  11  4  1  1           1
  </code></pre>
  
  <p>But I want to table look like this;</p>
  
  <pre><code>    A  B  C  B_max  B_min
  0   1  5  1  7        4 
  1   1  7  1  7        4
  2   1  6  1  7        4
  3   1  4  1  7        4
  4   2  5  1  8        6
  5   2  8  1  8        6
  6   2  6  1  8        6
  7   3  7  1  9        7
  8   3  9  1  9        7
  9   4  6  1  7        1
  10  4  7  1  7        1
  11  4  1  1  7        1
  </code></pre>
  
  <p>interpret the code for the result to look like this</p>