I'm trying to add a column to a dataframe
In yf_test.csv
I have two columns:
import pandas as pd
import yfinance as yf
ticker = pd.read_csv('yf_test.csv')
filtered = ticker['Filter1']
alist = []
for x in filtered:
y = yf.Ticker(x)
z = y.history(start=str(pnldate),end=str(pnldate))
alist.append(z)
yf_data = pd.concat(alist)
price = yf_data['Close']
ticker['price']=price
What I wanted to do is to pull the prices from Yahoo Finance and then have them populate in a new column on dataframe ticker
.
But when I do the above, I get an error:
ValueError: cannot reindex from a duplicate axis
What is the best way to achieve this?