Skip to content

Conversation

@usmanmohammed
Copy link
Contributor

@usmanmohammed usmanmohammed commented Jul 23, 2020

Fixes #600

I think it could be beneficial to show more examples on how to manipulate data frames.

Union of two data frames

DataFrame unionDf = df.Union(df);
unionDf.Show();

+----+-------+
| age|   name|
+----+-------+
|null|Michael|
|  30|   Andy|
|  19| Justin|
|null|Michael|
|  30|   Andy|
|  19| Justin|
+----+-------+

Add new column

df.WithColumn("location", Lit("Seattle")).Show();

+----+-------+--------+
| age|   name|location|
+----+-------+--------+
|null|Michael| Seattle|
|  30|   Andy| Seattle|
|  19| Justin| Seattle|
+----+-------+--------+

Rename existing column

df.WithColumnRenamed("name", "fullname").Show();

+----+--------+
| age|fullname|
+----+--------+
|null| Michael|
|  30|    Andy|
|  19|  Justin|
+----+--------+

Filter null rows in age column

df.Filter(Col("age").IsNull()).Show();

+----+-------+
| age|   name|
+----+-------+
|null|Michael|
+----+-------+

Fill null values in age column with -1

df.Na().Fill(-1, new[] { "age" }).Show();

+---+-------+
|age|   name|
+---+-------+
| -1|Michael|
| 30|   Andy|
| 19| Justin|
+---+-------+

Drop age column

df.Drop(new[] { "age" }).Show();

+-------+
|   name|
+-------+
|Michael|
|   Andy|
| Justin|
+-------+

Copy link
Contributor

@imback82 imback82 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @usmanmohammed!

@imback82 imback82 merged commit 01433ca into dotnet:master Jul 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE REQUEST]: Add more Data Frame examples

2 participants