【发布时间】:2021-03-09 21:48:11
【问题描述】:
如标题。
我已经编写了我的代码,但它不起作用。我希望我能获得一种更 Pythonic 的方式来编写代码(也许在一行中)。
clean_df:
columnA
123F
FVGD
w999Z
678Q
6y6yA
我的代码:
postfix = ["A", "D", "Z", "P"]
for value in postfix:
if cleaned_data['columnA'].str.endswith(value) is True:
cleaned_data['columnA'] = value
else:
cleaned_data['columnA'] = "blah"
postfix 是不变的。预期结果:
columnA
blah
D
Z
blah
A
【问题讨论】:
标签: python regex pandas dataframe