Skip to content
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

Implemented last_valid_index for DataFrame and Series #1705

Merged
merged 4 commits into from Aug 25, 2020

Conversation

itholic
Copy link
Contributor

@itholic itholic commented Aug 11, 2020

This PR proposes an implementation of DataFrame.last_valid_index and Series.last_valid_index

# DataFrame
>>> kdf = ks.DataFrame({'a': [1, 2, 3, None],
...                     'b': [1.0, 2.0, 3.0, None],
...                     'c': [100, 200, 400, None]},
...                     index=['Q', 'W', 'E', 'R'])
>>> kdf
     a    b      c
Q  1.0  1.0  100.0
W  2.0  2.0  200.0
E  3.0  3.0  400.0
R  NaN  NaN    NaN

>>> kdf.last_valid_index()
'E'

# Series
>>> s = ks.Series([1, 2, 3, None, None], index=[100, 200, 300, 400, 500])
>>> s
100    1.0
200    2.0
300    3.0
400    NaN
500    NaN
Name: 0, dtype: float64

>>> s.last_valid_index()
300

@HyukjinKwon HyukjinKwon merged commit d274748 into databricks:master Aug 25, 2020
HyukjinKwon pushed a commit that referenced this pull request Aug 25, 2020
Quick fix for build failure. The PR #1705 have failed since It made conflicts with #1712 .

`Series` has no more default name `0`,  we should not include it to the result.

- previous behaviour
```python
>>> s = ks.Series([1, 2, 3, None, None], index=[100, 200, 300, 400, 500])
>>> s
100    1.0
200    2.0
300    3.0
400    NaN
500    NaN
name: 0, dtype: float64
```

- current behaviour
```python
>>> s = ks.Series([1, 2, 3, None, None], index=[100, 200, 300, 400, 500])
>>> s
100    1.0
200    2.0
300    3.0
400    NaN
500    NaN
dtype: float64
```
@itholic itholic deleted the last_valid_index branch September 10, 2020 11:44
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.

None yet

2 participants