Python panderaでUnion型を扱う方法 pandera (0.18.0) ではUnion型がサポートされていなさげ。そのためちょっとだけ自分でコードを書く必要がある。例えばあるカラムが文字列or数値であることを検証するには、以下のようにすればよい。from datetime im... 2024.02.24 Python
Python DataFrameのmapとかapplyとか DataFrameのmapとかapplyとか、いろいろあって間違えがちなので、メモimport pandas as pdimport polars as pldf = (適当に作成)# pandas の場合df['a'].map(lambd... 2022.12.12 Python
Python DataFrameの手動ソートのトリック df.col = df.col.astype("category")df.col.cat.set_categories(sorted_list, inplace=True)df = df.sort_values(["col"]).reset... 2021.06.18 Python
Python pythonでExcel作成 # 桁区切りのカンマありの整数format_int = {'num_format': '#,##0', 'align': 'right'}# 小数点以下2桁format_flt = {'num_format': '#,##0.00', 'a... 2021.02.27 Python
Python DataFrameとCOALESCE # df1(id, col) # df2(id, col)やりたきこと:df1をdf2で更新-- SQLSELECTCOALESCE(b.id, a.id) AS id, COALESCE(b.col, a.col) AS colFROM ... 2020.10.29 Python