1
票
承認済み
PandasのDataFrame.applyメソッドで、データがゼロ件のときの処理方法について
コメントでのアドバイスを参考に、以下のようにresult_type='reduce'を指定することでゼロ件の場合はapplyを適用する関数は呼び出されなくなりました。
さらに、applyの結果はゼロ件のSeriesを戻すようになり、期待した結果が得られました。
series = df.apply(concat_col, axis='columns', result_type='reduce')
Only top scored, non community-wiki answers of a minimum length are eligible
関連するタグ
pandas × 420python × 400
python3 × 95
numpy × 31
matplotlib × 28
csv × 26
seaborn × 6
json × 5
正規表現 × 4
機械学習 × 4
excel × 4
web-scraping × 4
google-colaboratory × 4
r × 3
jupyter-notebook × 3
anaconda × 3
selenium × 3
dataframe × 3
postgresql × 2
pip × 2
mecab × 2
scikit-learn × 2
テキストファイル × 2
scipy × 2
openpyxl × 2