2

I have a folder which contain files like

  dm.csv
  ae.csv
  ex.csv

I want to read all file in one go without specifying file name into pandas with dataframe name as dm, ae, ex respectively.

I have tried different methods like use libraries

 dask.dataframe.read_csv
 glob.glob
 os.listdir

every method indicating concat of all dtaframes but i want individually

1
  • Use globand list. Commented Jan 30, 2019 at 7:06

1 Answer 1

2

Now you cannot create variable names on fly. But what you can do is create a dictionary of dataframes with key as your file name.

from os import listdir
from os.path import isfile, join
import pandas as pd
mypath = 'folder path'
files = [f.split('.')[0] for f in listdir(mypath) if isfile(join(mypath, f))]

dataframe={}
for file in files:
     dataframe[file] = pd.read_csv(mypath+file+'.csv')#provide separator if required
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.