Loading...

verticapy.vDataFrame.dropna

vDataFrame.dropna(columns: Annotated[str | list[str], 'STRING representing one column or a list of columns'] | None = None) vDataFrame

Filters the specified vDataColumns in a vDataFrame for missing values.

Parameters

columns: SQLColumns, optional

List of the vDataColumns names. If empty, all vDataColumns are selected.

Returns

vDataFrame

self

Examples

We import verticapy:

import verticapy as vp

Hint

By assigning an alias to verticapy, we mitigate the risk of code collisions with other libraries. This precaution is necessary because verticapy uses commonly known function names like “average” and “median”, which can potentially lead to naming conflicts. The use of an alias ensures that the functions from verticapy are used as intended without interfering with functions from other libraries.

For this example, we will use the Titanic dataset:

from verticapy.datasets import load_titanic

vdf = load_titanic()

In the above dataset, notice that the first and last entries are identical i.e. duplicates.

Note

VerticaPy offers a wide range of sample datasets that are ideal for training and testing purposes. You can explore the full list of available datasets in the Datasets, which provides detailed information on each dataset and how to use them effectively. These datasets are invaluable resources for honing your data analysis and machine learning skills within the VerticaPy environment.

We can see the count of each column to check if any column has missing values.

vdf.count()
count
"pclass"1234.0
"survived"1234.0
"name"1234.0
"sex"1234.0
"age"997.0
"sibsp"1234.0
"parch"1234.0
"ticket"1234.0
"fare"1233.0
"cabin"286.0
"embarked"1232.0
"boat"439.0
"body"118.0
"home.dest"706.0

From the above table, we can see that there are multiple columns with missing/NA values.

Using dropna, we can select which columns do we want the dataset to filter by:

vdf.dropna(columns = ["fare", "embarked", "age"])
1 element was filtered.
Out[4]: 
None  pclass    ...    survived                           home.dest  
1          1    ...           0                 Montevideo, Uruguay  
2          1    ...           0                         Trenton, NJ  
3          1    ...           0                 Montevideo, Uruguay  
4          1    ...           0                     Los Angeles, CA  
5          1    ...           0                        Lakewood, NJ  
6          1    ...           0                        Montreal, PQ  
7          1    ...           0    Deephaven, MN / Cedar Rapids, IA  
8          1    ...           0                        New York, NY  
9          1    ...           0                        Scituate, MA  
10         1    ...           0                                None  
11         1    ...           0                        New York, NY  
12         1    ...           0                                None  
13         1    ...           0                  London / Middlesex  
14         1    ...           0                        New York, NY  
15         1    ...           0                     Springfield, MA  
16         1    ...           0                       Vancouver, BC  
17         1    ...           0                      Dorchester, MA  
18         1    ...           0                      Washington, DC  
19         1    ...           0                       Lexington, MA  
20         1    ...           0               Surbiton Hill, Surrey  
...      ...    ...         ...                                 ...  
Rows: 1-20 of 994 | Columns: 3
123
pclass
Int
100%
...
123
survived
Int
100%
Abc
home.dest
Varchar(100)
65%
11...0Montevideo, Uruguay
21...0Trenton, NJ
31...0Montevideo, Uruguay
41...0Los Angeles, CA
51...0Lakewood, NJ
61...0Montreal, PQ
71...0Deephaven, MN / Cedar Rapids, IA
81...0New York, NY
91...0Scituate, MA
101...0[null]
111...0New York, NY
121...0[null]
131...0London / Middlesex
141...0New York, NY
151...0Springfield, MA
161...0Vancouver, BC
171...0Dorchester, MA
181...0Washington, DC
191...0Lexington, MA
201...0Surbiton Hill, Surrey

Now again, if we look at the count, we will notice that the total count has decreased.

vdf.count()
count
"pclass"994.0
"survived"994.0
"name"994.0
"sex"994.0
"age"994.0
"sibsp"994.0
"parch"994.0
"ticket"994.0
"fare"994.0
"cabin"261.0
"embarked"994.0
"boat"380.0
"body"116.0
"home.dest"648.0

See also

vDataFrame.balance() : Balances the vDataFrame.
vDataFrame.drop() : Drops the vDataFrame input columns.