Skip to content

Commit

Permalink
docs: update fill_null documentation with detailed usage examples
Browse files Browse the repository at this point in the history
  • Loading branch information
kosiew committed Feb 24, 2025
1 parent b28756f commit 5ce9a27
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions docs/source/library-user-guide/using-the-dataframe-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,17 +198,19 @@ async fn main() -> Result<()> {
}
```

[`custom_file_format.rs`]: https://github.com/apache/datafusion/blob/main/datafusion-examples/examples/custom_file_format.rs
## Fill Null Values with DataFrame::fill_null

The output file will look like (Example Output):
The `fill_null` method allows you to replace null values in specified columns with a provided value. When an empty list of columns is passed, the operation is applied to all columns. The method only fills if the given value can be cast to the column's data type.

```sql
> select * from '../datafusion/core/example.parquet';
+---+---+---+
| a | b | c |
+---+---+---+
| 1 | 2 | 3 |
+---+---+---+
**Usage Example:**

```rust
// Fill nulls in specific columns "a" and "c":
let df = ctx.read_csv("tests/data/example.csv", CsvReadOptions::new()).await?;
let df = df.fill_null(ScalarValue::from(0), vec!["a".to_owned(), "c".to_owned()])?;

// Fill nulls across all columns:
let df = df.fill_null(ScalarValue::from(0), vec![])?;
```

## Relationship between `LogicalPlan`s and `DataFrame`s
Expand Down

0 comments on commit 5ce9a27

Please sign in to comment.