我有一个dataframe dfdata,它有一个字段“fieldname”,其中包含字符串数据,子字符串条目像“then value”。我想用类似“then value end”的内容替换这些条目。问题是不同行的“值”不同,字符串包含多个“)”。所以呢结构更换不起作用。我在想也许回复sub使用通配符,但我需要通配符值在替换中显示。我在想我可能需要写一个循环。有人知道一个巧妙的方法吗?我有下面的示例数据和输出。你知道吗
Example Data:
import pandas as pd
dfdata = pd.DataFrame({'fieldname1': ['Bob', 'Jane'],
'fieldname2': ['Other words when spaghetti then turnip), do this)', 'Different other words when tomato then ketchup)']})
Example Output:
import pandas as pd
dfdata = pd.DataFrame({'fieldname1': ['Bob', 'Jane'],
'fieldname2': ['Other words when spaghetti then turnip end), do this)', 'Different other words when tomato then ketchup end)']})
IIUC公司:
相关问题 更多 >
编程相关推荐