Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/345.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 验证检查,不包括增值税、增值税和总给予错误_Python_Pandas_Dataframe - Fatal编程技术网

Python 验证检查,不包括增值税、增值税和总给予错误

Python 验证检查,不包括增值税、增值税和总给予错误,python,pandas,dataframe,Python,Pandas,Dataframe,我有以下建议: ExclBTW BTW Totaal NaN NaN 750.0 我正在试着对不包括的增值税、增值税和总额进行验证检查。 使用以下代码: #validation check df1.loc[:, ['ExclBTW', 'BTW','Totaal']] = df[['ExclBTW', 'BTW','Totaal']].apply(lambda x: x.astype(float)) df1['Totaal'] = df[['ExclBTW', 'BT

我有以下建议:

ExclBTW   BTW    Totaal
  NaN     NaN   750.0
我正在试着对不包括的增值税、增值税和总额进行验证检查。 使用以下代码:

#validation check
df1.loc[:, ['ExclBTW', 'BTW','Totaal']] = df[['ExclBTW', 'BTW','Totaal']].apply(lambda x: x.astype(float))
df1['Totaal'] = df[['ExclBTW', 'BTW','Totaal']].\
                  apply(lambda x: x['Totaal'] if x['Totaal'] == (x['ExclBTW'] + x['BTW']) else np.nan, axis=1)
当值被填充时,这工作正常!但是,当使用空值时,python会出现以下错误:

    116 
    117 #validation check
--> 118 df1.loc[:, ['ExclBTW', 'BTW','Totaal']] = df[['ExclBTW', 'BTW','Totaal']].apply(lambda x: x.astype(float))
    119 df1['Totaal'] = df[['ExclBTW', 'BTW','Totaal']].\
    120                   apply(lambda x: x['Totaal'] if x['Totaal'] == (x['ExclBTW'] + x['BTW']) else np.nan, axis=1)

    ValueError: could not convert string to float: ''

Is there any way to work around this?
我试图填补NaN的空缺:

#df1['BTW'] = df1['BTW'].fillna(float(1))
#df1['ExclBTW'] = df1['BTW'].fillna(float(1))
#df1['ExclBTW'] = df1['ExclBTW'].fillna(df1['Totaal'])
不幸的是,这不起作用

请帮助按所有列使用,然后:

cols = ['ExclBTW', 'BTW','Totaal']
df1[cols] = df[cols].apply(lambda x: pd.to_numeric(x, erros='coerce'))

df1['Totaal'] = np.where(df['Totaal'] == df['ExclBTW'] + df['BTW'], df['Totaal'], np.nan)