Skip to content

Commit

Permalink
updated docstrings for class DataFrame (#270)
Browse files Browse the repository at this point in the history
  • Loading branch information
mfonekpo authored Jun 9, 2024
1 parent f1a3187 commit f82c0f2
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions narwhals/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,17 +195,22 @@ class DataFrame(BaseFrame):
Examples:
Constructing a DataFrame from a dictionary:
>>> import pandas as pd
>>> import polars as pl
>>> import narwhals as nw
>>> data = {"a": [1, 2], "b": [3, 4]}
>>> df_pl = pl.DataFrame(data)
>>> df = nw.DataFrame(df_pl)
>>> df
┌───────────────────────────────────────────────┐
| Narwhals DataFrame |
| Use `narwhals.to_native` to see native output |
└───────────────────────────────────────────────┘
>>> nw.to_native(df)
>>> df_pd = pd.DataFrame(data)
we define a library-agnostic function:
>>> def func(df_any):
... df = nw.from_native(df_any)
... return nw.to_native(df)
You can pass either pandas or Polars to the function `func`:
>>> func(df_pl)
shape: (2, 2)
┌─────┬─────┐
│ a ┆ b │
Expand All @@ -215,6 +220,12 @@ class DataFrame(BaseFrame):
│ 1 ┆ 3 │
│ 2 ┆ 4 │
└─────┴─────┘
>>> func(df_pd)
a b
0 1 3
1 2 4
"""

def __init__(
Expand Down

0 comments on commit f82c0f2

Please sign in to comment.