1
$\begingroup$

I think the title is enough for what is my problem here. I have 100 tickers in a folder. I got all csv files to one list. but I wanna see the tickers name which these are csv file names. enter image description here

what should I do for getting all tickers like that. I'm doing it manually but I need a simple way to do that.

import pandas as pd
import os

#BİST100-2010.01.01-2020.07.01/ is my folder.
log_total = []
for file in os.listdir('BİST100-2010.01.01-2020.07.01/'):
    log_total.append(pd.read_csv('BİST100-2010.01.01-2020.07.01/'+file+''))

by the way after I do that I got this.

enter image description here

$\endgroup$
1
  • $\begingroup$ pd.DataFrame(log_total) ? if it doesnt work create an empty dataframe and concatenate. If it doesn't work maybe try to build the csv directly on multiple ticker... $\endgroup$
    – lcrmorin
    Oct 22 at 12:59
1
$\begingroup$

How do you get to the second picture from that code? I wil give you rough set of steps to follow along with the main function names. you can search through the pandas documentation for more details.

  1. initialise some empty lists: ticker_names=[] dataframes=[]
  2. Loop over the files and read them using df = pd.read_csv(file_name)
  3. Take just the Close column of each single ticker's dataframe: df = df["Close"]
  4. Keep track of the tickers' names in a list: ticker_names.append(ticker)
  5. Bring them all together into one dataframe: final_df = pd.concat(dataframes, left_index=True, right_index=True). We uses the indices because you have date-time index values, and we want to keep them all.
  6. Then give each column the correct name: final_df.columns = ticker_names

You can play around with each of these steps, and I would suggest looking at the **pd.merge** documentation.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.