I have a list like this:
(我有一个这样的清单:)
x = ['Las Vegas', 'San Francisco, 'Dallas']
And a dataframe that looks a bit like this:
(还有一个看起来像这样的数据框:)
import pandas as pd
data = [['Las Vegas (Clark County), 25], ['New York', 23],
['Dallas', 27]]
df = pd.DataFrame(data, columns = ['City', 'Value'])
I want to replace my city values in the DF "Las Vegas (Clark County)" with "Las Vegas" .
(我想将DF “拉斯维加斯(克拉克县)”中的城市值替换为“ Las Vegas” 。)
In my dataframe are multiple cities with different names which needs to be changed. (在我的数据框中,有多个城市名称不同,需要更改。)
I know I could do a regex expression to just strip off the part after the parentheses, but I was wondering if there was a more clever, generic way. (我知道我可以做一个正则表达式来删除括号后的部分,但是我想知道是否有更聪明的通用方法。)
ask by Kevin translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…