ValueError:无结果DataFrame-熊猫

时间:2018-08-02 15:10:25

标签: python pandas

这是我的代码。

import os
import pandas as pd

file='Requirements Upload.xlsx'
x1=pd.ExcelFile(file)
df=x1.parse('Requirements Mapping')

agg_df = (df.fillna('N/A').set_index(['Unique_ID', 'No_of_Filings'])
          .stack()
          .reset_index('No_of_Filings')
          .groupby(0)
          .agg(['sum', 'size'])
          .reset_index())

writer=pd.ExcelWriter("Requirements Output.xlsx",engine="xlsxwriter")
agg_df.to_excel(writer,"Requirements Mapping Output")

writer.save()

这是我的数据:

Unique_ID   No_of_Filings   Req_1   Req_2   Req_3   Req_4
RCONF045    3               Blue    Yellow      
RCONF046    3               Blue    Yellow      
RCONF047    3               Blue    Yellow      
RCONF048    3               Green   Brown       
RCONF051    3               Green   Purple  Orange  Black
RCONF052    3               Green   Purple  Orange  Blue

运行代码时,我的错误是“ ValueError:无结果”,但我不明白为什么。空白单元格会引起问题吗?

编辑:我已经为所有空白单元格添加了“ NA”,但仍然收到相同的错误。

第二编辑:我的原始文件正在使用公式提取这些字段。我吹掉了要上传到Python中的公式,但是当我打印数据框时,它会将那些空字段保留下来(即使我的上传文件中没有公式)。我删除了这些行,现在可以了!

      Unique_ID  No_of_Filings  Req_1   Req_2   Req_3  Req_4
  0   RCONF045            3.0   Blue  Yellow     NaN    NaN
  1   RCONF046            3.0   Blue  Yellow     NaN    NaN
  2   RCONF047            3.0   Blue  Yellow     NaN    NaN
  3   RCONF048            3.0  Green   Brown     NaN    NaN
  4   RCONF051            3.0  Green  Purple  Orange  Black
  5   RCONF052            3.0  Green  Purple  Orange   Blue
  6        NaN            NaN    NaN     NaN     NaN    NaN
  7        NaN            NaN    NaN     NaN     NaN    NaN
  8        NaN            NaN    NaN     NaN     NaN    NaN
  9        NaN            NaN    NaN     NaN     NaN    NaN
  10       NaN            NaN    NaN     NaN     NaN    NaN

谢谢!

0 个答案:

没有答案