2012-06-01 33 views
46

Ho un dataFrame in panda e molte delle colonne hanno tutti valori nulli. C'è una funzione integrata che mi consentirà di rimuovere quelle colonne?Rimuovere le colonne NULL in un dataframe Panda?

Grazie!

+0

si potrebbe forse accettare la risposta? Questo segnerà la domanda come risolta e aiuterà anche altri utenti. – MERose

risposta

82

Sì, dropna. Vedere http://pandas.pydata.org/pandas-docs/stable/missing_data.html e la DataFrame.dropna docstring:

Definition: DataFrame.dropna(self, axis=0, how='any', thresh=None, subset=None) 
Docstring: 
Return object with labels on given axis omitted where alternately any 
or all of the data are missing 

Parameters 
---------- 
axis : {0, 1} 
how : {'any', 'all'} 
    any : if any NA values are present, drop that label 
    all : if all values are NA, drop that label 
thresh : int, default None 
    int value : require that many non-NA values 
subset : array-like 
    Labels along other axis to consider, e.g. if you are dropping rows 
    these would be a list of columns to include 

Returns 
------- 
dropped : DataFrame 

il comando specifico per l'esecuzione potrebbe essere:

df=df.dropna(axis=1,how='all') 
+0

puoi specificare il valore 'dropna'? per esempio potresti rilasciare file che sono tutti zeri? – zach

+6

potresti definire con i parser di pandas io che il tuo valore NaN in tabelle di input dati è 0, OPPURE, potresti preparare il tuo passo in questo modo: 'df [df == 0] = np.nan; df = df.dropna (asse = 1, come = 'all') ' –

Problemi correlati