@@ -12466,11 +12466,6 @@ def first_valid_index(self) -> Hashable | None:
12466
12466
-------
12467
12467
type of index
12468
12468
12469
- Notes
12470
- -----
12471
- If all elements are non-NA/null, returns None.
12472
- Also returns None for empty {klass}.
12473
-
12474
12469
Examples
12475
12470
--------
12476
12471
For Series:
@@ -12481,6 +12476,22 @@ def first_valid_index(self) -> Hashable | None:
12481
12476
>>> s.last_valid_index()
12482
12477
2
12483
12478
12479
+ >>> s = pd.Series([None, None])
12480
+ >>> print(s.first_valid_index())
12481
+ None
12482
+ >>> print(s.last_valid_index())
12483
+ None
12484
+
12485
+ If all elements in Series are NA/null, returns None.
12486
+
12487
+ >>> s = pd.Series()
12488
+ >>> print(s.first_valid_index())
12489
+ None
12490
+ >>> print(s.last_valid_index())
12491
+ None
12492
+
12493
+ If Series is empty, returns None.
12494
+
12484
12495
For DataFrame:
12485
12496
12486
12497
>>> df = pd.DataFrame({{'A': [None, None, 2], 'B': [None, 3, 4]}})
@@ -12493,6 +12504,31 @@ def first_valid_index(self) -> Hashable | None:
12493
12504
1
12494
12505
>>> df.last_valid_index()
12495
12506
2
12507
+
12508
+ >>> df = pd.DataFrame({{'A': [None, None, None], 'B': [None, None, None]}})
12509
+ >>> df
12510
+ A B
12511
+ 0 None None
12512
+ 1 None None
12513
+ 2 None None
12514
+ >>> print(df.first_valid_index())
12515
+ None
12516
+ >>> print(df.last_valid_index())
12517
+ None
12518
+
12519
+ If all elements in DataFrame are NA/null, returns None.
12520
+
12521
+ >>> df = pd.DataFrame()
12522
+ >>> df
12523
+ Empty DataFrame
12524
+ Columns: []
12525
+ Index: []
12526
+ >>> print(df.first_valid_index())
12527
+ None
12528
+ >>> print(df.last_valid_index())
12529
+ None
12530
+
12531
+ If DataFrame is empty, returns None.
12496
12532
"""
12497
12533
return self ._find_valid_index (how = "first" )
12498
12534
0 commit comments