这是我的代码:
def cost_channelID(received_frame):
received_frame.columns = ['Ad', 'Impressions', 'eCPM', 'Ad Spend']
Ads = received_frame['Ad']
ID = []
for ad in Ads:
num = re.findall(r'\d{6}',ad)
ID.append(num)
ID = pd.Series(ID)
return(ID)
输出如下:
[111234]
[111235]
......
[111444]
我希望输出没有括号:
111234
111235
......
144444
答案 0 :(得分:0)
从Python中获取序列中的单个元素非常简单
num = re.findall(r'\d{6}',ad)[0]
虽然我考虑过为什么re.findall
(返回序列的方法)首先被使用。