pandas_series
Table of Contents
dummy
append element to series
In [1]: import pandas as pd s = pd.Series(dtype='int') N = 4 for i in range(N): s.at[i**2] = i print(s) 0 0 1 1 4 2 9 3 dtype: int64 In [2]: pd.__version__ Out[2]: '1.2.1'
check if
check if a series is empty
Use pandas.Series.empty .
$ ipython In [1]: import pandas as pd import numpy as np df1 = pd.DataFrame({'A': []}) df1 Out[1]: Empty DataFrame Columns: [A] Index: [] In [2]: df1['A'].empty Out[2]: True
A series with just NaNs is considered “non-empty”. Drop the NaNs to make it “empty”.
In [3]: df2 = pd.DataFrame({'A': [np.nan]}) df2 Out[3]: A 0 NaN In [4]: df2['A'].empty Out[4]: False In [5]: df2['A'].dropna().empty Out[5]: True
Used Python 3.9.4 and IPython 7.22.0
tags | check if a series has at least one element
pandas_series.txt · Last modified: 2021/09/15 20:07 by raju