简体   繁体   中英

Append Dataframe inside the loop - Python

I am trying append dataframe inside the loop after reading the file, but still not appending full dataset.

columns = list(df)
data= []

for file in glob.glob("*.html"):
   df = pd.read_html(file)[2]
   
   zipped_date = zip(columns , df.values)
        
   a_dictionary = dict(zipped_date)
        
   data.append(a_dictionary)

full_df = full_df .append(data, False)

Maybe create a list of dataframes inside the loop and the concat them:

for file in glob.glob("*.html"):
   data.append( pd.read_html(file)[2] )

full_df = pd.concat(data, ignore_index=True)

使用 pd.concat:

df = pd.concat([pd.read_html(file)[2] for files in glob.glob("*.html")])

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