Importing Multiple Data-frames with Pandas

流过昼夜 提交于 2021-02-10 16:48:22

问题


I'm trying to import multiple datasets into a single data frame through a function.

# function to import each of the new datasets 
def csvImport(yearOfDataset):
import glob, os
for items in yearOfDataset:
    # dataset name 
    ds = pd.concat(map(pd.read_csv, glob.glob(os.path.join("PSNI_StreetCrime_"+str(yearOfDataset)),"*.csv")))

I want to pass the argument to the function as follows, as it means I can call it quicker for the multiple folders I have; The folder name follow the pattern ChildFolder_YYYY

csvImport('2014')

When running the above, these are the errors being returned.

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-61-bba2086ac576> in <module>()
----> 1 csvImport('2014')

<ipython-input-56-0459a8272784> in csvImport(yearOfDataset)
  2 def csvImport(yearOfDataset):
  3     import glob, os
----> 4     sd = pd.concat(map(pd.read_csv, glob.glob(os.path.join("Datasets/PSNI_StreetCrime_"+yearOfDataset),"*.csv")))

TypeError: glob() takes 1 positional argument but 2 were given

I'm new to Pandas, and semi-new to Python so help would be greatly appreciated, the various changes I've tried have been unsuccessful.

来源:https://stackoverflow.com/questions/52841784/importing-multiple-data-frames-with-pandas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!