我有一个数据帧,其数据格式如下:
name,type
P1,["prod_1", "prod_3"]
P2,["prod_2", "prod_3"]
P3,None
我正在尝试将其转换为以下输出:
name,type
P1,"prod_1", "prod_3"
P2,"prod_2", "prod_3"
P3,None
df['type']
的数据类型是object
我尝试使用正则表达式,如下所示:
df['type'] = df['type'].replace("[", df['type'])
df['type'] = df['type'].replace("]", df['type'])
但这仍然返回相同的输出,前后用括号括起来
用这个
订单号:
文件:https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.str.replace.html
str.replace
接收regex作为替换模式,|
在这里用作or
和\
转义字符在这里用来区别regex字符正如@Jon Clements所说,
strip
将是解决这个问题的最佳选择。你知道吗相关问题 更多 >
编程相关推荐