title: Python Pandas mean and weighted Average
body: <p>I am new to python pandas.
  Any help will be much appreciated</p>
  
  <p>This is my raw data:</p>
  
  <pre><code>         Feed  Close  Sector  Market_Cap
  Date
  2015-09-18 A   5.60  Property  50    
  2015-09-21 A   5.60  Property  20    
  2015-09-23 A   5.60  Property  30    
  2015-09-18 ABC 0.67  Property  50    
  2015-09-21 ABC 0.66  Property  80     
  2015-09-18 DA  0.67  Mining    65    
  2015-09-21 KK  1.66  Mining    80    
  </code></pre>
  
  <p>what I would like to get is this:</p>
  
  <p>1 Create a new column call Mean to calculate average market Cap for each feed.    </p>
  
  <p>2  Find weighted average.  </p>
  
  <pre><code>This is what I want:
           Feed  Close  Sector   Market_Cap   Mean   Sector_WeightedAvg
  Date
  2015-09-18 A   5.60  Property  50           33.33      33.33/(33.33+65) 
  2015-09-21 A   5.60  Property  20           33.33      33.33/(33.33+65)
  2015-09-23 A   5.60  Property  30           33.33      33.33/(33.33+65)
  2015-09-18 ABC 0.67  Property  50           65         65/(33.33+65)
  2015-09-21 ABC 0.66  Property  80           65         65/(33.33+65) 
  2015-09-18 DA  0.67  Mining    65           62         62/(62+80)
  2015-09-21 KK  1.66  Mining    80           80         80/(62+80)
  </code></pre>
  
  <p>This is my current code for mean which I get NaN:</p>
  
  <pre><code>df3= pd.DataFrame(df3)
  df3['Mean'] = df3.groupby(by=['Sector'])[ Market_Cap].mean()  
  
           Feed  Close  Sector   Market_Cap   Mean   
  Date
  2015-09-18 A   5.60  Property  50           NaN       
  2015-09-21 A   5.60  Property  20           NaN      
  2015-09-23 A   5.60  Property  30           NaN      
  2015-09-18 ABC 0.67  Property  50           NaN             
  </code></pre>
  
  <p>and for weighted average code:</p>
  
  <pre><code>df2['WeightedAverage'] =df3[ Market_Cap].value /df3['Mean'].value
  </code></pre>
  
  <p>I got the error:</p>
  
  <blockquote>
    <p>AttributeError: 'Series' object has no attribute 'value'</p>
  </blockquote>