python - Python:使用数据框从字符串中提取子字符串
问题描述
试图从字符串中提取子字符串。为单个记录工作,但为多个记录获取 NAN。
预期输出:
1st Row:HKA-33711-15293045
2nd row:HKA-94612-14661285
代码尝试:
df1['o_position'] = df1['Event Value'].str.find('HKA-')
df1['o_position_to_18'] = df1['o_position']+18
df1["order_id"]=df1["Event Value"].str.slice(start=df1["o_position"],stop=df1['o_position_to_18'])
df1.head()
数据:
{'"af_currency"':'"INR"','"af_revenue"':429,'"af_customer_user_id"':'"33738413"','"af_price"':['"399"'],'"af_receipt_id"':'"HKA-33711-15293045"','"af_content_id"':['"72769"'],'"sessionId"':'"-1551484318545"','"af_quantity"':['"1"'],'"af_param_1"':'"HKA-33711-15293045"','"af_content_type"':'"order"'}
第二行:
{'"af_price"':['"2199"'],'"af_content_id"':['"72289"'],'"af_quantity"':['"1"'],'"af_param_1"':'"HKA-94612-14661285"','"af_content_type"':'"order"','"af_currency"':'"INR"','"af_revenue"':2199,'"af_receipt_id"':'"HKA-94612-14661285"'}
解决方案
推荐阅读
- java - 如何解决 Java 中的编码问题?
- r - 使用按列分组识别行中的差异
- reactjs - React: Unable to access and test props & state during Jest/Enzyme shallow rendering
- android - set center_horizontal for child of FrameLayout
- google-maps - 用于识别道路阻塞/封闭标志的 Google API
- rabbitmq - rabbitmq 的健康检查
- amazon-ec2 - AWS EC2 - 获取通过 RDP 登录的 AWS EC2 实例的访问日志
- angular - 使用离子 4 找不到角管
- c# - 新的 OLEDB 驱动程序 (MSOLEDBSQL) 无法在 sql server 中存储日期时间 (.fff) 的一小部分
- php - 在 PHP 中使用 MySQL 数据进行搜索和排序