为什么 python 中的 pandas 没有 return 来自 excel sheet 的所有行?
why pandas in python does not return all the rows from excel sheet?
这是我的代码,我的 excel sheet 有 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)
代码来自:
这是我的代码,我的 excel sheet 有 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)
代码来自: