則刪除df列如果列中的所有值都爲「0%」,我想從熊貓數據框中刪除給定列。python pandas:如果條件爲
我DF:
data = {'UK': ['11%', '16%', '7%', '52%', '2%', '5%', '3%', '3%'],
'US': ['0%', '0%', '0%', '0%', '0%', '0%', '0%', '0%'],
'DE': ['11%', '16%', '7%', '52%', '2%', '5%', '3%', '3%'],
'FR': ['11%', '16%', '7%', '52%', '2%', '5%', '3%', '3%']
}
dummy_df = pd.DataFrame(data,
index= ['cat1','cat2','cat3','cat4','cat5','cat6','cat7','cat8'],
columns=['UK', 'US', 'DE', 'FR'])
到目前爲止我的代碼:
dummy_df.drop(dummy_df == '0%',inplace=True)
我得到一個值誤差:
ValueError: labels ['UK' 'US' 'DE' 'FR'] not contained in axis
相關的問題[刪除數據幀行中熊貓基於列的值] (http://stackoverflow.com/questions/18172851/deleting-dataframe-row-in-pandas-based-on-column-value) – farhawa