Skip to content

docstring update #1100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 56 additions & 77 deletions janitor/functions/fill.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,50 +20,36 @@ def fill_direction(df: pd.DataFrame, **kwargs) -> pd.DataFrame:
and `downup`.


Functional usage syntax:

```python
import pandas as pd
import janitor as jn

df = pd.DataFrame(...)
df = jn.fill_direction(
df = df,
column_1 = direction_1,
column_2 = direction_2,
)
```

Method-chaining usage syntax:

>>> import pandas as pd
>>> import janitor as jn
>>> df = pd.DataFrame(
... {
... 'col1': [1, 2, 3, 4],
... 'col2': [None, 5, 6, 7],
... 'col3': [8, 9, 10, None],
... 'col4': [None, None, 11, None],
... 'col5': [None, 12, 13, None]
... }
... )
>>> df
col1 col2 col3 col4 col5
0 1 NaN 8.0 NaN NaN
1 2 5.0 9.0 NaN 12.0
2 3 6.0 10.0 11.0 13.0
3 4 7.0 NaN NaN NaN
>>> df.fill_direction(
... col2 = 'up',
... col3 = 'down',
... col4 = 'downup',
... col5 = 'updown'
... )
col1 col2 col3 col4 col5
0 1 5.0 8.0 11.0 12.0
1 2 5.0 9.0 11.0 12.0
2 3 6.0 10.0 11.0 13.0
3 4 7.0 10.0 11.0 13.0
Example:

>>> import pandas as pd
>>> import janitor as jn
>>> df = pd.DataFrame(
... {
... 'col1': [1, 2, 3, 4],
... 'col2': [None, 5, 6, 7],
... 'col3': [8, 9, 10, None],
... 'col4': [None, None, 11, None],
... 'col5': [None, 12, 13, None]
... }
... )
>>> df
col1 col2 col3 col4 col5
0 1 NaN 8.0 NaN NaN
1 2 5.0 9.0 NaN 12.0
2 3 6.0 10.0 11.0 13.0
3 4 7.0 NaN NaN NaN
>>> df.fill_direction(
... col2 = 'up',
... col3 = 'down',
... col4 = 'downup',
... col5 = 'updown'
... )
col1 col2 col3 col4 col5
0 1 5.0 8.0 11.0 12.0
1 2 5.0 9.0 11.0 12.0
2 3 6.0 10.0 11.0 13.0
3 4 7.0 10.0 11.0 13.0

:param df: A pandas DataFrame.
:param kwargs: Key - value pairs of columns and directions.
Expand Down Expand Up @@ -138,39 +124,32 @@ def fill_empty(

This method mutates the original DataFrame.

Functional usage syntax:

```python
df = fill_empty(df, column_names=[col1, col2], value=0)
```

Method chaining syntax:


>>> import pandas as pd
>>> import janitor
>>> df = pd.DataFrame(
... {
... 'col1': [1, 2, 3],
... 'col2': [None, 4, None ],
... 'col3': [None, 5, 6]
... }
... )
>>> df
col1 col2 col3
0 1 NaN NaN
1 2 4.0 5.0
2 3 NaN 6.0
>>> df.fill_empty(column_names = 'col2', value = 0)
col1 col2 col3
0 1 0.0 NaN
1 2 4.0 5.0
2 3 0.0 6.0
>>> df.fill_empty(column_names = ['col2', 'col3'], value = 0)
col1 col2 col3
0 1 0.0 0.0
1 2 4.0 5.0
2 3 0.0 6.0
Example:

>>> import pandas as pd
>>> import janitor
>>> df = pd.DataFrame(
... {
... 'col1': [1, 2, 3],
... 'col2': [None, 4, None ],
... 'col3': [None, 5, 6]
... }
... )
>>> df
col1 col2 col3
0 1 NaN NaN
1 2 4.0 5.0
2 3 NaN 6.0
>>> df.fill_empty(column_names = 'col2', value = 0)
col1 col2 col3
0 1 0.0 NaN
1 2 4.0 5.0
2 3 0.0 6.0
>>> df.fill_empty(column_names = ['col2', 'col3'], value = 0)
col1 col2 col3
0 1 0.0 0.0
1 2 4.0 5.0
2 3 0.0 6.0


:param df: A pandas DataFrame.
Expand Down
64 changes: 32 additions & 32 deletions janitor/functions/update_where.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,38 +24,38 @@ def update_where(

Example usage:

>>> data = {
... "a": [1, 2, 3, 4],
... "b": [5, 6, 7, 8],
... "c": [0, 0, 0, 0],
... }
>>> df = pd.DataFrame(data)
>>> df
a b c
0 1 5 0
1 2 6 0
2 3 7 0
3 4 8 0
>>> df.update_where(
... conditions = (df.a > 2) & (df.b < 8),
... target_column_name = 'c',
... target_val = 10
... )
a b c
0 1 5 0
1 2 6 0
2 3 7 10
3 4 8 0
>>> df.update_where( # supports pandas *query* style string expressions
... conditions = "a > 2 and b < 8",
... target_column_name = 'c',
... target_val = 10
... )
a b c
0 1 5 0
1 2 6 0
2 3 7 10
3 4 8 0
>>> data = {
... "a": [1, 2, 3, 4],
... "b": [5, 6, 7, 8],
... "c": [0, 0, 0, 0],
... }
>>> df = pd.DataFrame(data)
>>> df
a b c
0 1 5 0
1 2 6 0
2 3 7 0
3 4 8 0
>>> df.update_where(
... conditions = (df.a > 2) & (df.b < 8),
... target_column_name = 'c',
... target_val = 10
... )
a b c
0 1 5 0
1 2 6 0
2 3 7 10
3 4 8 0
>>> df.update_where( # supports pandas *query* style string expressions
... conditions = "a > 2 and b < 8",
... target_column_name = 'c',
... target_val = 10
... )
a b c
0 1 5 0
1 2 6 0
2 3 7 10
3 4 8 0

:param df: The pandas DataFrame object.
:param conditions: Conditions used to update a target column
Expand Down