I can load multiple stock tickers from yahoo finance, but I am having trouble adding new columns before it is saved to a csv
<p>The code below starts by uploading data from yahoo finance in pnls. It does this successufly. Then I have code where I want to add columns to the loaded data in pnls. This part is unsuccessful. Finally I want to save pnls to a csv file which it does successfully if the column changes are not in the code.</p>

<p>The question that I need answered is how do I successfully make multiple column changes before I save pnls to csv??</p>

<pre><code>from pandas_datareader import data as dreader
import pandas as pd
from datetime import datetime
import numpy as np

# Symbols is a list of all the ticker symbols that I am downloading from yahoo finance
symbols = ['tvix','pall','pplt','sivr','jju','nib','jo','jjc','bal','jjg','ld','cdw','gaz','jjn','pgm',
           'sgg','jjt','grn','oil','gld','corn','soyb','weat','uhn','uga','bunl','jgbl','bndx','aunz',
           'cemb','emhy','vwob','ald','udn','fxa','fxb'] 

#This gets the data from yahoo finance 
pnls = {i:dreader.DataReader(i,'yahoo','1985-01-01',datetime.today()) for i in symbols}

 # These are the new columns that I want to add
pnls['PofChg'] = ((pnls.Close - pnls.Open) / (pnls.Open)) * 100 
pnls['U_D_F']  = np.where(pnls.PofChg &gt; 0 , 'Up', np.where(pnls.PofChg == 0, 'Flat', 'Down'));pnls
pnls['Up_Down']   = pnls.Close.diff()
pnls['Close%pd']  = pnls.Close.pct_change()*100


# This saves the current ticker to a csv file
for df_name in pnls:
    pnls.get(df_name).to_csv("{}_data.csv".format(df_name), index=True, header=True)
</code></pre>

<p>This is the error that I get when I run the code</p>

<pre><code>Traceback (most recent call last):
  File "YahooFinanceDataGetter.py", line 14, in &lt;module&gt;
    pnls['PofChg'] = ((pnls.Close - pnls.Open) / (pnls.Open)) * 100
AttributeError: 'dict' object has no attribute 'Close'
Press any key to continue . . .
</code></pre>

<p>The line</p>

<pre><code>pnls = {i:dreader.DataReader(i,'yahoo','1985-01-01',datetime.today()) for i in symbols}
</code></pre>

<p>builds a python <code>dict</code> (using <a href="http://stackoverflow.com/questions/14507591/python-dictionary-comprehension">dictionary comprehension</a>). To check this, you can run the following:</p>

<pre><code>assert type(pnls) == dict
</code></pre>

<p>This is what the error message is telling you: <code>AttributeError: 'dict' object has no attribute 'Close'</code>.</p>

<p>The DataFrames are actually the values of the dictionary. To apply transformations to them, you can iterate over the <code>values()</code> of the dictionary:</p>

<pre><code>for df in pnls.values():
    df = ((df.Close - df.Open) / (df.Open)) * 100 
    ...
</code></pre>

python csv pandas dataframe