課題
以下のページを参考に、CSVファイルのデータの一部(*)をAに置換したいと考えています。
regex=Trueにしましたが、置換できませんでした。
解決方法を教えていただけると嬉しいです。
https://it-ojisan.tokyo/pandas-replace-regex/
https://note.nkmk.me/python-pandas-replace/
コード
python
# -*- coding: utf-8 -*- import pandas as pd LOAD_CSV_PATH = './test.csv' df1 = pd.read_csv(LOAD_CSV_PATH, dtype="string") print("df1") print(df1) """ A B C 0 11 21 31 1 12 22 32 2 *13 *23 *33 3 14 24 34 """ # *を除去 df2 = pd.read_csv(LOAD_CSV_PATH, dtype="string") df2 = df2.replace("*", "A", regex=True) print(df2) """ A B C 0 11 21 31 1 12 22 32 2 *13 *23 *33 3 14 24 34 """
まだ回答がついていません
会員登録して回答してみよう