pandas vs FiftyOne¶
This cheat sheet shows how to translate common pandas operations into FiftyOne.
Nomenclature¶
pandas |
FiftyOne |
---|---|
DataFrame ( |
Dataset ( |
Row |
Sample |
Column |
Field |
Getting started¶
pandas |
FiftyOne |
|
---|---|---|
Importing the packages |
|
|
Create empty dataset |
|
|
Load dataset |
|
|
Basics¶
pandas |
FiftyOne |
|
---|---|---|
First row/sample |
|
|
Last row/sample |
|
|
First few rows/samples |
|
|
Last few rows/samples |
|
|
Get specific row/sample |
|
|
Number of rows/samples |
|
|
Column names/field schema |
|
|
Get all values in column/field |
|
|
View stages¶
pandas |
FiftyOne |
|
---|---|---|
Make a copy |
|
|
Slice |
|
|
Random sample |
|
|
Shuffle data |
|
|
Filter by column/field value |
|
|
Sort values |
|
|
Delete all |
import gc del df; gc.collect() |
|
Aggregations¶
pandas |
FiftyOne |
|
---|---|---|
Count |
|
|
Sum |
|
|
Unique values |
|
|
Bounds |
min = df[*].min() max = df[*].max() |
|
Mean |
|
|
Standard deviation |
|
|
Quantile |
|
|
Structural changes¶
pandas |
FiftyOne |
|
---|---|---|
New column/field as constant value |
|
ds.add_sample_field("field", fo.StringField) ds.set_field("field", value).save() |
New column/field from external data |
|
|
New column/field from existing columns/fields |
|
ds.add_sample_field("field", fo.FloatField) ds.set_field("field", expression).save() |
Remove a column/field |
|
ds.delete_sample_fields(["field"]) ords.exclude_fields(["field"]).keep_fields() |
Keep only specified columns/fields |
|
|
Concatenate DataFrames or DatasetViews |
|
|
Add a single row/sample |
|
|
Remove rows/samples |
|
ds.delete_samples(sample_ids) ords.exclude(samples).keep() |
Keep only specified rows/samples |
|
|
Rename column/field |
|
|
Expressions¶
pandas |
FiftyOne |
|
---|---|---|
Exact equality |
|
|
Less than or equal to |
|
|
Logical complement |
|
|
Logical AND |
|
|
Logical OR |
|
|
Is in |
|
|
Contains string |
|
|
Check for numerics |
|
isinstance(ds.get_field_schema()[*], (fo.FloatField, fo.IntField)) orlen(ds.match(F(*).is_number())) > 0 |
Check for strings |
|
isinstance(ds.get_field_schema()[*], fo.StringField) orlen(ds.match(F(*).is_string())) > 0 |
Check for null entries |
|
|
Note
The table above assumes you have imported:
import pandas.api.types as pdt
from fiftyone import ViewField as F