Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
297 views
in Technique[技术] by (71.8m points)

How to read csv files from a folder and delete them immediately in python

I have many csv files in one a folder - "C:DataInput_Files"

I would like to load only few csv files whose name starts with "chunk".

The naming of csv files are chunk1, chunk2,chunk3,------,chunk150. While loading I want to append all of them into a single file (don't want to read all the files and then append).

Once the loading is done into python as single data frame, I would like to delete those csv files (chunk1,chunk2,--,chunk150) in my input folder "C:DataInput_Files"

I am using the below syntax. But is reading all csv files.

path = r'C:DataInput_Files'

all_files = 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_)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...