[英]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")])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.