Create DataFrame from Loop with Bloomberg function
<p>I have a list of company ticker's:</p>

<pre><code>df = {'Ticker': ['AVON LN EQUITY', 'GFS LN EQUITY'], 'Value': [1., 2.]}
df = pd.DataFrame(df)
</code></pre>

<p>I am using the BLPAPI wrapper, <a href="https://github.com/alex314159/blpapiwrapper" rel="nofollow">https://github.com/alex314159/blpapiwrapper</a></p>

<p>Using this i would like to get a DataFrame, of all the prices over on a monthly basis. For this i am using the BLP class and BDH function. Settings below (the longer version is in the link):</p>

<pre><code>def bdh(self, strSecurity='SPX Index', strData='PX_LAST', startdate=datetime.date(2013, 1, 1), enddate=datetime.date(2016, 9, 6),
        adjustmentSplit=False, periodicity='MONTHLY', strOverrideField='', strOverrideValue=''):
</code></pre>

<p>for simplicity i created a mini function:</p>

<pre><code>def bloom_func(x, func):
    bloomberg = BLP()
    return bloomberg.bdh(x, func, strOverrideField='BEST_FPERIOD_OVERRIDE', strOverrideValue='1GY' )
    bloomberg.closeSession()
</code></pre>

<p>Using these i can get a DataFrame for one equity. </p>

<pre><code>Price = bloom_func('VOD LN EQUITY', 'PX_LAST')
print (c)
</code></pre>

<p>which works. </p>

<p>However, when i try to run this in a across the 2 companies using:</p>

<pre><code>df1 = pd.concat([df.apply(lambda x: bloom_func(x)) for p in df['Ticker']])
</code></pre>

<p>i get ValueError: Shape of passed values is (2, 0), indices imply (2, 2). </p>

<p>Was simpler than I thought</p>

<pre><code>for d in df['Ticker']:
    x[d] = bloom_func(d)
</code></pre>

python pandas bloomberg