I am trying to read an excel file this way :
newFile = pd.ExcelFile(PATH\FileName.xlsx)
ParsedData = pd.io.parsers.ExcelFile.parse(newFile)
Run Code Online (Sandbox Code Playgroud)
which throws an error that says two arguments expected, I don't know what the second argument is and also what I am trying to achieve here is to convert an Excel file to a DataFrame, Am I doing it the right way? or is there any other way to do this using pandas?
我有一个.csv包含多个表的文件.
使用熊猫,这将是拿到两个数据帧的最佳策略inventory,并HPBladeSystemRack从这个文件?
输入.csv看起来像这样:
Inventory
System Name IP Address System Status
dg-enc05 Normal
dg-enc05_vc_domain Unknown
dg-enc05-oa1 172.20.0.213 Normal
HP BladeSystem Rack
System Name Rack Name Enclosure Name
dg-enc05 BU40
dg-enc05-oa1 BU40 dg-enc05
dg-enc05-oa2 BU40 dg-enc05
Run Code Online (Sandbox Code Playgroud)
到目前为止,我提出的最好的方法是将此.csv文件转换为Excel工作簿(xlxs),将表拆分为表并使用:
inventory = read_excel('path_to_file.csv', 'sheet1', skiprow=1)
HPBladeSystemRack = read_excel('path_to_file.csv', 'sheet2', skiprow=2)
Run Code Online (Sandbox Code Playgroud)
然而:
xlrd模块.我看过很多与我的问题相关的帖子,但找不到正确的解决方案。 读取包含多个表格的Excel工作表,表格的标题具有非白色背景单元格颜色
到目前为止我已经尝试过:
import pandas as pd
df = pd.read_excel("dell.xlsx")
df =df.dropna()
Run Code Online (Sandbox Code Playgroud)
上面的代码删除了想要的数据,因为它有 nan。
df.iloc[1,2:5]=['Description','Qty','Price']
print(df)
nul_rows = list(df[df.isnull().all(axis=1)].index)
list_of_dataframes = []
for i in range(len(nul_rows) - 1):
list_of_dataframes.append(df.iloc[nul_rows[i]+1:nul_rows[i+1],:])
cleaned_tables = []
for _df in list_of_dataframes:
cleaned_tables.append(_df.dropna(axis=1, how='all'))
for p in cleaned_tables:
print(p.dropna())
Run Code Online (Sandbox Code Playgroud)
无法获取我想要的数据,因为这些数据不是标头格式,而是未命名的。
我想从链接中的Excel中提取这些数据“Sku描述”“数量”“价格”“总计”。
希望我能得到一些回应。
笔记!文件内容和格式始终不同,因此基于一个文件的解决方案不能用于下一个文件,但标题名称不会更改,例如数量、描述、总计。