teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

追記

2018/02/28 04:48

投稿

8524ba23
8524ba23

スコア38352

answer CHANGED
@@ -1,7 +1,12 @@
1
- `t1`が列(`Series`)を指しているならば[.str.replace](https://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.str.replace.html)を使ってください。
1
+ `t1`が列(`Series`)を指しているならば[PandasSeries.str.replace](https://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.str.replace.html)を使ってください。
2
+ ちなみに`t1.replace('(株)','株式会社')`だと[pandas.Series.replace](https://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.replace.html)が呼ばれstrである「(株)」との**完全一致**で判定されるので「(株)aaa」が置換されません。
3
+
4
+ > str: string exactly matching to_replace will be replaced with value
5
+
2
6
  ```Python
3
7
  import pandas as pd
4
8
  df = pd.DataFrame({'col1':['(株)','(株)aaa', '株式会社']})
5
9
  df['col1'] = df['col1'].str.replace('(株)','株式会社')
10
+ #df['col1'] = df['col1'].replace('(株)','株式会社',regex=True) # こちらでも可。regex=Trueを指定。
6
11
  print(df)
7
12
  ```