課題
以下のページを参考に、CSVファイルのデータの一部(*)をAに置換したいと考えています。
regex=Trueにしましたが、置換できませんでした。
解決方法を教えていただけると嬉しいです。
https://it-ojisan.tokyo/pandas-replace-regex/
https://note.nkmk.me/python-pandas-replace/
コード
python
1# -*- coding: utf-8 -*- 2import pandas as pd 3 4LOAD_CSV_PATH = './test.csv' 5 6 7df1 = pd.read_csv(LOAD_CSV_PATH, dtype="string") 8print("df1") 9print(df1) 10 11""" 12 A B C 130 11 21 31 141 12 22 32 152 *13 *23 *33 163 14 24 34 17""" 18 19# *を除去 20df2 = pd.read_csv(LOAD_CSV_PATH, dtype="string") 21df2 = df2.replace("*", "A", regex=True) 22print(df2) 23""" 24 A B C 250 11 21 31 261 12 22 32 272 *13 *23 *33 283 14 24 34 29""" 30

回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。