繁体   English   中英

为什么 python 中的 pandas 不返回 excel 工作表中的所有行?

[英]why pandas in python does not return all the rows from excel sheet?

这是我的代码,我的 excel 工作表有 1000 行和 22 列数据。 我想将 excel 转换为文本文件。 但是当我运行这个时,我只得到第一个和第 5 行和第 5 行的数据列? 如何解决这个问题

import pandas as pd
xlsFile = pd.ExcelFile(r'C:/Users/vivek/OneDrive/Desktop/College Project/modules/spreadSheetManipulation/sample.xlsx')
totalPages= xlsFile.sheet_names
with open(r'C:/Users/vivek/OneDrive/Desktop/College Project/modules/spreadSheetManipulation/output.txt','w') as textFile:
    for page in totalPages:
        dataFrame = xlsFile.parse(page)
        textFile.write("\nSheet name is:"+page+"\n")
        textFile.write(str(dataFrame))
        textFile.write('\n')

你可以尝试这样的事情

import pandas as pd

with open(r'C:/Users/vivek/OneDrive/Desktop/College Project/modules/spreadSheetManipulation/sample.xlsx', 'w') as file:
    pd.read_excel(r'C:/Users/vivek/OneDrive/Desktop/College Project/modules/spreadSheetManipulation/output.txt').to_string(file, index=False)

代码来自: Convert.xlsx to.txt with python? 或 format.txt 文件来修复列缩进?

暂无
暂无

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

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