Skip to content

Commit aaae4d7

Browse files
authored
doc: Move dataframe! example into dedicated example (#16197)
1 parent 68e26f1 commit aaae4d7

1 file changed

Lines changed: 21 additions & 6 deletions

File tree

docs/source/user-guide/dataframe.md

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,27 @@ use datafusion::prelude::*;
5050

5151
Here is a minimal example showing the execution of a query using the DataFrame API.
5252

53+
Create DataFrame using macro API from in memory rows
54+
55+
```rust
56+
use datafusion::prelude::*;
57+
use datafusion::error::Result;
58+
59+
#[tokio::main]
60+
async fn main() -> Result<()> {
61+
// Create a new dataframe with in-memory data using macro
62+
let df = dataframe!(
63+
"a" => [1, 2, 3],
64+
"b" => [true, true, false],
65+
"c" => [Some("foo"), Some("bar"), None]
66+
)?;
67+
df.show().await?;
68+
Ok(())
69+
}
70+
```
71+
72+
Create DataFrame from file or in memory rows using standard API
73+
5374
```rust
5475
use datafusion::arrow::array::{Int32Array, RecordBatch, StringArray};
5576
use datafusion::arrow::datatypes::{DataType, Field, Schema};
@@ -84,12 +105,6 @@ async fn main() -> Result<()> {
84105
let df = ctx.read_batch(batch)?;
85106
df.show().await?;
86107

87-
// Create a new dataframe with in-memory data using macro
88-
let df = dataframe!(
89-
"id" => [1, 2, 3],
90-
"name" => ["foo", "bar", "baz"]
91-
)?;
92-
df.show().await?;
93108
Ok(())
94109
}
95110
```

0 commit comments

Comments
 (0)