[英]write console output to excel sheet using DataFrame python
for foo in root.finadall(xpath):
print (foo.name[xpath], foo.country[xpath])
df = DataFrame({'Name': foo.name[xpath], 'conutry': foo.country[xpath]})
df.to_excel('foo.xlsx', sheet_name='sheet1', index=False)
The output prints the lots of names in the console.输出会在控制台中打印大量名称。 But In excel, It stores only the least one.
但是在excel中,它只存储最少的一个。 How do i store all the names in the excel.
如何将所有名称存储在excel中。
To get on clear idea:要获得清晰的想法:
The console output:
Name Country
jennfier abc
andy john cde
carwl xyz
In excel i see the only carwl xyz.在excel中,我看到了唯一的carwl xyz。
You are overwriting your excel file in each iteration of the loop, so try to collect all your data first, then generate a single DataFrame based on collected data and save it as Excel您在循环的每次迭代中都覆盖了您的 excel 文件,因此请尝试先收集所有数据,然后根据收集的数据生成单个 DataFrame 并将其保存为 Excel
DataFrame({'Name': collected_data_list}).to_excel('foo.xlsx', sheet_name='sheet1', index=False)
PS you should really provide a sample and desired data sets if you want to have neat answers... PS,如果您想得到简洁的答案,您应该真正提供示例和所需的数据集...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.