pandas dataframe詳細エラー

684 ワード

仕事中に2つのpandasのバグに遭遇し、連環のエラーが発生するので記録しておきます
1.dataframe(df)が空であると仮定すると、df.to_csv(tmpfile)エラーNone of[xxx]in columns
従って、出力時にdfが空であるか否かを判断する必要がある
たとえば
df = df[df['a‘] == 0]  (                  df.a          “()”)
#      
#      if not df ,   “The truth value of a DataFrame is ambiguous”
if df.shape[0] == 0 :
	return None
else:
	return df

2.前のステップでは、別の関数で戻り値が必要であると仮定し、同様に判断する必要があります.ここでも何回かエラーが発生しました.
#      df    
if not df:
	   “The truth value of a DataFrame is ambiguous”
if df.shape[0]==0:
	   none has no attribute shape
"""     """
if df is none:
	return none
else:
	df = xxxxx(    )