我正在尝试根据分隔符拆分行,但无法获得正确的结果。有人可以帮我怎么做吗?
示例:
df1:
rule_id priority_order comb_fld_order
R162 2.3 1
R162 2.3.1 1
R162 2.6 2
R162 2.6.1 2
R162 3.0.4 3.2,3.1,3
预期结果:
df2:
rule_id priority_order comb_fld_order comb_fld_order_1
R162 2.3 1 1
R162 2.3.1 1 1
R162 2.6 2 2
R162 2.6.1 2 2
R162 3.0.4 3.2,3.1,3 3.2
R162 3.0.4 3.2,3.1,3 3.1
R162 3.0.4 3.2,3.1,3 3
我正在编写用于生成df1的代码:
conn = redshift_conn()
cur = conn.cursor()
query = '''select rule_id,priority_order,comb_fld_order from medaff.imedical_business_rules_metadata WHERE RULE_ID='R162' and comb_fld_order is not null order by priority_order'''
cur.execute(query)
res = cur.fetchall()
column_names = [i[0] for i in cur.description]
df = pd.DataFrame(res, columns=column_names)