我想在“ at”一词的一列中拆分文本
这是我的df:
Job
Operation Manager at Barclays
Chief Operating Officer at Llyods
实际上是数千个单元格,但这只是一个快照。
这就是我想要的:
Job Location
Operating Manager Barclays
Chief Operating Officer Llyods
这是我尝试过的:
df2 = pd.DataFrame(df.Job.str.split('at',1).tolist(), columns = ['Job','Location'])
这就是我得到的(不是我想要的):
Job Location
Oper ating Manager at Barclays
Chief Oper ating Officer at Llyods
因此它在'at'处拆分,但在第一个单词中遇到了字符串'at'。我希望它分裂为“ at”一词。有办法吗?
我尝试了以下操作,但不起作用:
df2 = pd.DataFrame(df.Job.str.split(' at ',1).tolist(), columns = ['Job','Location'])
我明白了:
Job Location
Operating Manager at Barclays None
Chief Operating Officer at Llyods None
谢谢
答案 0 :(得分:2)
使用airflow.cfg
例如:
[api]
auth_backend = my_app.deny_all_auth_backend # or the actual path to your module
输出:
str.split(r"\bat\b", expand=True)
答案 1 :(得分:0)
尝试一下:
df2Init = df.Job.str.split(' at ',1, expand=True).rename({0:'Job', 1:'Location'},axis=1).to_dict()
df2 = pd.DataFrame(data=df2Init)