【发布时间】:2020-04-15 00:04:42
【问题描述】:
我是 Python 新手,我有一个数据框,我想从中提取字符串开头的数字。例如:
import numpy as np
import pandas as pd
Test = {'Text': ['/CY1000 HZ 23 Street Arizona','/3456 BZ 33 Rue Avenue France','/2222 6th Street Madrid', np.nan],
'Price': [22000,25000,27000,35000]}
df = pd.DataFrame(Test,columns= ['Text', 'Price'])
我想将 1000,3456,2222,NaN 放在另一列中,并将其余文本放在另一列中
Test = {'Text': ['/CY1000 HZ 23 Street Arizona','/3456 BZ 33 Rue Avenue France','/2222 6th Street Madrid', np.nan],
'Text1': ['1000','3456','2222',np.nan],
'Price': [22000,25000,27000,35000],
'Text2': [ 'HZ 23 Street Arizona', 'BZ 33 Rue Avenue France','6th Street Madrid', 'Nan']}
df = pd.DataFrame(Test,columns= ['Text', 'Text1','Text2','Price'])
提前致谢
【问题讨论】:
标签: python regex string dataframe