本文簡要介紹
pyspark.pandas.DataFrame.first_valid_index
的用法。用法:
DataFrame.first_valid_index() → Union[int, float, bool, str, bytes, decimal.Decimal, datetime.date, datetime.datetime, None, Tuple[Union[int, float, bool, str, bytes, decimal.Decimal, datetime.date, datetime.datetime, None], …]]
檢索第一個有效值的索引。
- 標量、元組或無
返回:
例子:
支持DataFrame
>>> psdf = ps.DataFrame({'a': [None, 2, 3, 2], ... 'b': [None, 2.0, 3.0, 1.0], ... 'c': [None, 200, 400, 200]}, ... index=['Q', 'W', 'E', 'R']) >>> psdf a b c Q NaN NaN NaN W 2.0 2.0 200.0 E 3.0 3.0 400.0 R 2.0 1.0 200.0
>>> psdf.first_valid_index() 'W'
支持MultiIndex 列
>>> psdf.columns = pd.MultiIndex.from_tuples([('a', 'x'), ('b', 'y'), ('c', 'z')]) >>> psdf a b c x y z Q NaN NaN NaN W 2.0 2.0 200.0 E 3.0 3.0 400.0 R 2.0 1.0 200.0
>>> psdf.first_valid_index() 'W'
支持係列。
>>> s = ps.Series([None, None, 3, 4, 5], index=[100, 200, 300, 400, 500]) >>> s 100 NaN 200 NaN 300 3.0 400 4.0 500 5.0 dtype: float64
>>> s.first_valid_index() 300
支持MultiIndex
>>> midx = pd.MultiIndex([['lama', 'cow', 'falcon'], ... ['speed', 'weight', 'length']], ... [[0, 0, 0, 1, 1, 1, 2, 2, 2], ... [0, 1, 2, 0, 1, 2, 0, 1, 2]]) >>> s = ps.Series([None, None, None, None, 250, 1.5, 320, 1, 0.3], index=midx) >>> s lama speed NaN weight NaN length NaN cow speed NaN weight 250.0 length 1.5 falcon speed 320.0 weight 1.0 length 0.3 dtype: float64
>>> s.first_valid_index() ('cow', 'weight')
相關用法
- Python pyspark DataFrame.first用法及代碼示例
- Python pyspark DataFrame.filter用法及代碼示例
- Python pyspark DataFrame.fillna用法及代碼示例
- Python pyspark DataFrame.foreachPartition用法及代碼示例
- Python pyspark DataFrame.foreach用法及代碼示例
- Python pyspark DataFrame.from_records用法及代碼示例
- Python pyspark DataFrame.floordiv用法及代碼示例
- Python pyspark DataFrame.ffill用法及代碼示例
- Python pyspark DataFrame.to_latex用法及代碼示例
- Python pyspark DataFrame.align用法及代碼示例
- Python pyspark DataFrame.plot.bar用法及代碼示例
- Python pyspark DataFrame.to_delta用法及代碼示例
- Python pyspark DataFrame.quantile用法及代碼示例
- Python pyspark DataFrame.cumsum用法及代碼示例
- Python pyspark DataFrame.iloc用法及代碼示例
- Python pyspark DataFrame.dropDuplicates用法及代碼示例
- Python pyspark DataFrame.printSchema用法及代碼示例
- Python pyspark DataFrame.to_table用法及代碼示例
- Python pyspark DataFrame.rmod用法及代碼示例
- Python pyspark DataFrame.div用法及代碼示例
- Python pyspark DataFrame.drop_duplicates用法及代碼示例
- Python pyspark DataFrame.to_pandas用法及代碼示例
- Python pyspark DataFrame.sum用法及代碼示例
- Python pyspark DataFrame.transform用法及代碼示例
- Python pyspark DataFrame.get用法及代碼示例
注:本文由純淨天空篩選整理自spark.apache.org大神的英文原創作品 pyspark.pandas.DataFrame.first_valid_index。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。