我只是想重命名“'位置”内的一些单元格。 pandas数据框中的列。
数据框的开头如下所示:
Apr 25 ASHEVILLE
Apr 25 ASHEVILLE
Apr 25 ASHEVILLE
Apr 25 ASHEVILLE
Apr 25 ASHEVILLE
Apr 25 ASHEVILLE
Apr 25 ASHEVILLE
Apr 25 ASHEVILLE
Apr 25 ASHEVILLE
Apr 25 ASHEVILLE
Apr 25 ASHEVILLE
Apr 25 ASHEVILLE
Apr 25 ASHEVILLE N C
Apr 25 ASHEVILLE N C
Apr 25 ASHEVILLE N C
我最好的猜测是:
postings.location = ["ASHEVILLE" for x in postings["location"] if "ASHEVILLE" in x]
但是我收到以下错误消息:
ValueError: Length of values does not match length of index
答案 0 :(得分:1)
您可以将.loc
与.str访问者和contains
一起使用:
postings.loc[postings.location.str.contains('ASHEVILLE'),'location'] = 'ASHEVILLE'