Skip to content

Commit 4bcfd6c

Browse files
authored
docstring update (#1100)
* docs update * docs update
1 parent 8ce6ab8 commit 4bcfd6c

File tree

2 files changed

+88
-109
lines changed

2 files changed

+88
-109
lines changed

janitor/functions/fill.py

Lines changed: 56 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -20,50 +20,36 @@ def fill_direction(df: pd.DataFrame, **kwargs) -> pd.DataFrame:
2020
and `downup`.
2121
2222
23-
Functional usage syntax:
24-
25-
```python
26-
import pandas as pd
27-
import janitor as jn
28-
29-
df = pd.DataFrame(...)
30-
df = jn.fill_direction(
31-
df = df,
32-
column_1 = direction_1,
33-
column_2 = direction_2,
34-
)
35-
```
36-
37-
Method-chaining usage syntax:
38-
39-
>>> import pandas as pd
40-
>>> import janitor as jn
41-
>>> df = pd.DataFrame(
42-
... {
43-
... 'col1': [1, 2, 3, 4],
44-
... 'col2': [None, 5, 6, 7],
45-
... 'col3': [8, 9, 10, None],
46-
... 'col4': [None, None, 11, None],
47-
... 'col5': [None, 12, 13, None]
48-
... }
49-
... )
50-
>>> df
51-
col1 col2 col3 col4 col5
52-
0 1 NaN 8.0 NaN NaN
53-
1 2 5.0 9.0 NaN 12.0
54-
2 3 6.0 10.0 11.0 13.0
55-
3 4 7.0 NaN NaN NaN
56-
>>> df.fill_direction(
57-
... col2 = 'up',
58-
... col3 = 'down',
59-
... col4 = 'downup',
60-
... col5 = 'updown'
61-
... )
62-
col1 col2 col3 col4 col5
63-
0 1 5.0 8.0 11.0 12.0
64-
1 2 5.0 9.0 11.0 12.0
65-
2 3 6.0 10.0 11.0 13.0
66-
3 4 7.0 10.0 11.0 13.0
23+
Example:
24+
25+
>>> import pandas as pd
26+
>>> import janitor as jn
27+
>>> df = pd.DataFrame(
28+
... {
29+
... 'col1': [1, 2, 3, 4],
30+
... 'col2': [None, 5, 6, 7],
31+
... 'col3': [8, 9, 10, None],
32+
... 'col4': [None, None, 11, None],
33+
... 'col5': [None, 12, 13, None]
34+
... }
35+
... )
36+
>>> df
37+
col1 col2 col3 col4 col5
38+
0 1 NaN 8.0 NaN NaN
39+
1 2 5.0 9.0 NaN 12.0
40+
2 3 6.0 10.0 11.0 13.0
41+
3 4 7.0 NaN NaN NaN
42+
>>> df.fill_direction(
43+
... col2 = 'up',
44+
... col3 = 'down',
45+
... col4 = 'downup',
46+
... col5 = 'updown'
47+
... )
48+
col1 col2 col3 col4 col5
49+
0 1 5.0 8.0 11.0 12.0
50+
1 2 5.0 9.0 11.0 12.0
51+
2 3 6.0 10.0 11.0 13.0
52+
3 4 7.0 10.0 11.0 13.0
6753
6854
:param df: A pandas DataFrame.
6955
:param kwargs: Key - value pairs of columns and directions.
@@ -138,39 +124,32 @@ def fill_empty(
138124
139125
This method mutates the original DataFrame.
140126
141-
Functional usage syntax:
142-
143-
```python
144-
df = fill_empty(df, column_names=[col1, col2], value=0)
145-
```
146-
147-
Method chaining syntax:
148-
149-
150-
>>> import pandas as pd
151-
>>> import janitor
152-
>>> df = pd.DataFrame(
153-
... {
154-
... 'col1': [1, 2, 3],
155-
... 'col2': [None, 4, None ],
156-
... 'col3': [None, 5, 6]
157-
... }
158-
... )
159-
>>> df
160-
col1 col2 col3
161-
0 1 NaN NaN
162-
1 2 4.0 5.0
163-
2 3 NaN 6.0
164-
>>> df.fill_empty(column_names = 'col2', value = 0)
165-
col1 col2 col3
166-
0 1 0.0 NaN
167-
1 2 4.0 5.0
168-
2 3 0.0 6.0
169-
>>> df.fill_empty(column_names = ['col2', 'col3'], value = 0)
170-
col1 col2 col3
171-
0 1 0.0 0.0
172-
1 2 4.0 5.0
173-
2 3 0.0 6.0
127+
Example:
128+
129+
>>> import pandas as pd
130+
>>> import janitor
131+
>>> df = pd.DataFrame(
132+
... {
133+
... 'col1': [1, 2, 3],
134+
... 'col2': [None, 4, None ],
135+
... 'col3': [None, 5, 6]
136+
... }
137+
... )
138+
>>> df
139+
col1 col2 col3
140+
0 1 NaN NaN
141+
1 2 4.0 5.0
142+
2 3 NaN 6.0
143+
>>> df.fill_empty(column_names = 'col2', value = 0)
144+
col1 col2 col3
145+
0 1 0.0 NaN
146+
1 2 4.0 5.0
147+
2 3 0.0 6.0
148+
>>> df.fill_empty(column_names = ['col2', 'col3'], value = 0)
149+
col1 col2 col3
150+
0 1 0.0 0.0
151+
1 2 4.0 5.0
152+
2 3 0.0 6.0
174153
175154
176155
:param df: A pandas DataFrame.

janitor/functions/update_where.py

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -24,38 +24,38 @@ def update_where(
2424
2525
Example usage:
2626
27-
>>> data = {
28-
... "a": [1, 2, 3, 4],
29-
... "b": [5, 6, 7, 8],
30-
... "c": [0, 0, 0, 0],
31-
... }
32-
>>> df = pd.DataFrame(data)
33-
>>> df
34-
a b c
35-
0 1 5 0
36-
1 2 6 0
37-
2 3 7 0
38-
3 4 8 0
39-
>>> df.update_where(
40-
... conditions = (df.a > 2) & (df.b < 8),
41-
... target_column_name = 'c',
42-
... target_val = 10
43-
... )
44-
a b c
45-
0 1 5 0
46-
1 2 6 0
47-
2 3 7 10
48-
3 4 8 0
49-
>>> df.update_where( # supports pandas *query* style string expressions
50-
... conditions = "a > 2 and b < 8",
51-
... target_column_name = 'c',
52-
... target_val = 10
53-
... )
54-
a b c
55-
0 1 5 0
56-
1 2 6 0
57-
2 3 7 10
58-
3 4 8 0
27+
>>> data = {
28+
... "a": [1, 2, 3, 4],
29+
... "b": [5, 6, 7, 8],
30+
... "c": [0, 0, 0, 0],
31+
... }
32+
>>> df = pd.DataFrame(data)
33+
>>> df
34+
a b c
35+
0 1 5 0
36+
1 2 6 0
37+
2 3 7 0
38+
3 4 8 0
39+
>>> df.update_where(
40+
... conditions = (df.a > 2) & (df.b < 8),
41+
... target_column_name = 'c',
42+
... target_val = 10
43+
... )
44+
a b c
45+
0 1 5 0
46+
1 2 6 0
47+
2 3 7 10
48+
3 4 8 0
49+
>>> df.update_where( # supports pandas *query* style string expressions
50+
... conditions = "a > 2 and b < 8",
51+
... target_column_name = 'c',
52+
... target_val = 10
53+
... )
54+
a b c
55+
0 1 5 0
56+
1 2 6 0
57+
2 3 7 10
58+
3 4 8 0
5959
6060
:param df: The pandas DataFrame object.
6161
:param conditions: Conditions used to update a target column

0 commit comments

Comments
 (0)