I am fairly new to Python and wanting some assistance with generating a new column called Ticker
when reading in multiple csv files. As the Yahoo! Finance API is depreciated, I am reading in csv data from Yahoo! Finance for 'GOOG', 'IBM' and 'AAPL'. The following code reads the individual csv files into one DateFrame, however, it is hard to distinguish which stock is which.
path =
allFiles = glob.glob(path + "/*.csv")
frame = pd.DataFrame()
list_ = []
for file in allFiles:
df = pd.read_csv(file,index_col=None,
header=0)
list_.append(df)
frame = pd.concat(list_)
frame.head()
Is it possible to create a column called Ticker
that has the name of the csv file for each observation for each stock? Eg. GOOG.csv is the file name for Google, IBM.csv is the file name for IBM...
This would make it easier to identify which stock is which.