简体   繁体   中英

Python - Read generic CSV (Pandas)

How can I read a file that ends with csv in a certain path?

import pandas as pd

df = pd.read_csv('C:\Users\*.csv')

Thanks

There are multiple ways of doing it. Here is my answer.Use glob module and make a for/while loop of all the files.

import glob

listcsv=glob.glob('C:\Users\*.csv')
for i in listcsv:
    df=pd.read_csv(i)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM