【发布时间】:2022-01-07 08:54:38
【问题描述】:
我正在使用参数调用以下函数。该参数是某些特定数据帧的键,存储在名为:iNms
的字典中我的函数目前如下所示: function
但我收到以下错误消息: fehler
当我打印左侧时,我得到“0”,而从右侧我得到一个“假” 我认为因此它不起作用。 我已经尝试转换右侧的条件,但错误仍然存在。
你有什么提示吗? 我完全是python新手(1-2周)只有一些理论知识,所以我尝试自己找出我的问题以获得学习经验。
现在我的代码和错误消息为 txt
第一次尝试时,我尝试了这个:
def check_missing_values(name):
if name in iNms:
if iNms[name].iloc[:,[0]].isnull().sum() == 0 and len(name)<8:
print('hurra')
with open('Log.txt','a') as w:
w.write('\n{}\t\t\tKeine fehlenden Primärschlüssel\tOK'.format(name))
elif iNms[name].iloc[:,[0]].isnull().sum() == 0 and 18>=len(name)>=8:
print('hurra2')
with open('Log.txt','a') as w:
w.write('\n{}\t\tKeine fehlenden Primärschlüssel\tOK'.format(name))
elif iNms[name].iloc[:,[0]].isnull().sum() != 0 and len(name)<8:
print('hurra3')
with open('Log.txt','a') as w:
w.write('\n{}\t\t\tEinige oder mehrere Primärschlüssel fehlen. Nicht OK. Nacharbeiten!'.format(name))
elif iNms[name].iloc[:,[0]].isnull().sum() !=0 and 18>=len(name)>=8:
print('hurra4')
with open('Log.txt','a') as w:
w.write('\n{}\t\tEinige oder mehrere Primärschlüssel fehlen. Nicht OK. Nacharbeiten!'.format(name))
else:
with open('Log.txt','a') as w:
if len(name)<17:
w.write('\n{}\t\tnicht angeliefert'.format(name))
else:
w.write('\n{}\tnicht angeliefert'.format(name))
print('Left side:',iNms['transaction'].iloc[:,[2]].isnull().sum())
print('Left side:',type(iNms['transaction'].iloc[:,[2]].isnull().sum()))
print('Right side:',len('transaction')<8)
print('Right side:',type(len('transaction')<8))
我的第二次尝试
def check_missing_values(name):
if name in iNms:
if (iNms[name].iloc[:,[0]].isnull().sum() == 0) & (len(name)<8):
print('hurra')
with open('Log.txt','a') as w:
w.write('\n{}\t\t\tKeine fehlenden Primärschlüssel\tOK'.format(name))
elif (iNms[name].iloc[:,[0]].isnull().sum() == 0) & (18>=len(name)>=8):
print('hurra2')
with open('Log.txt','a') as w:
w.write('\n{}\t\tKeine fehlenden Primärschlüssel\tOK'.format(name))
elif (iNms[name].iloc[:,[0]].isnull().sum() != 0) & (len(name)<8):
print('hurra3')
with open('Log.txt','a') as w:
w.write('\n{}\t\t\tEinige oder mehrere Primärschlüssel fehlen. Nicht OK. Nacharbeiten!'.format(name))
elif (iNms[name].iloc[:,[0]].isnull().sum() !=0) & (18>=len(name)>=8):
print('hurra4')
with open('Log.txt','a') as w:
w.write('\n{}\t\tEinige oder mehrere Primärschlüssel fehlen. Nicht OK. Nacharbeiten!'.format(name))
else:
with open('Log.txt','a') as w:
if len(name)<17:
w.write('\n{}\t\tnicht angeliefert'.format(name))
else:
w.write('\n{}\tnicht angeliefert'.format(name))
print('Left side:',iNms['transaction'].iloc[:,[2]].isnull().sum())
print('Left side:',type(iNms['transaction'].iloc[:,[2]].isnull().sum()))
print('Right side:',len('transaction')<8)
print('Right side:',type(len('transaction')<8))
我收到以下错误消息:
Left side: transaction_ts 0
dtype: int64
Left side: <class 'pandas.core.series.Series'>
Right side: False
Right side: <class 'bool'>
Traceback (most recent call last):
File "/home/tayfunuenver/Documents/Python/Parser_2.py", line 217, in <module>
check_missing_values('customer')
File "/home/tayfunuenver/Documents/Python/Parser_2.py", line 174, in check_missing_values
if iNms[name].iloc[:,[0]].isnull().sum() == 0 and len(name)<8:
File "/home/tayfunuenver/.local/lib/python3.6/site-packages/pandas/core/generic.py", line 1330, in __nonzero__
f"The truth value of a {type(self).__name__} is ambiguous. "
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
【问题讨论】:
-
请将您的函数和完整的错误消息粘贴为文本。粘贴图像会使人们更难复制粘贴和重现您的问题。
-
好吧,你是对的。当我回到家时,我会这样做。
-
我现在更新了我的问题。
标签: python-3.x pandas conditional-statements isnull