简体   繁体   English

我想从 csv 文件中提取字符串的某些部分

[英]I would like to extract certain part of a string from csv file

I have vast number of columns containing this kind of data:我有大量包含此类数据的列:

DE-JP-202/2066/A2@qwier.cu/68
NL-LK-02206/2136/A1@ozmmfts.de/731
OM-PH-31303222/3671/Z1@jtqy.ml/524

I would like to extract string between '@' and '.'我想提取'@'和'.'之间的字符串and between '.'在“。”之间and '/' into two separete colums.和 '/' 分成两个单独的列。

Like:喜欢:

txt 1      txt 2
qwier       cu
ozmmft      de
jtqy        ml

Tried:试过:

x = dane.str.extract(r'@(?P<txt1>\d)\.(?P<txt2>[ab\d])/')

But doesn't work但不起作用

If you want to get 2 capturing groups, you could use 2 negated character classes .如果你想获得 2 个捕获组,你可以使用 2 negated character classes

In the first group match 1+ times any char except a dot [^.]+在第一组中,除点[^.]+之外的任何字符都匹配 1 次以上

In the second group match 1+ times any char except a forward slash [^/]+在第二组比赛中,除正斜杠[^/]+之外的任何字符 1 次以上

@(?P<txt1>[^.]+)\.(?P<txt2>[^/]+)/

Regex demo正则表达式演示

If the formatting of your strings all have only 1 @ and 1 .如果您的字符串格式都只有 1 @和 1 . . . You can do the following:您可以执行以下操作:

s = 'DE-JP-202/2066/A2@qwier.cu/68'

column1 = s.split('@')[1].split('.')[0]

column2 = s.split('@')[1].split('.')[1].split('/')[0]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从元组到字符串提取csv文件的一部分? - How to extract a part of a csv file, from tuple to a string? 我想从txt文件中提取x和y值 - I would like to extract x and y values from a txt file 我想从 csv 文件中获取数据 - I would like to take a data from in the csv file 我正在读取 csv 文件并以字符串中的字符串结尾(类似于“88456”)。 如何提取 int 值? - I am reading from a csv file and ending up with a string within a string (something like this ' "88456" '). How do I extract the int value? 我想将“:”中的单词提取为斜杠 - I would like to extract the words from “:” to slash python:提取字符串的某些部分 - python:extract certain part of string 我想将字符串的第一部分切在&#39;|&#39;之前 - I would like to slice the first part of a string before the '|' 在 CSV 文件中。 我想使用 df.loc 提取几个值,并使用 python 将计算公式应用于这些值中的每一个 - in CSV file. I would like to extract several values using df.loc and apply the calculation formula to each of these values using python 从文件中读取字符串的某些部分 - Read certain part of string from file 在不使用熊猫的情况下,如何分析CSV数据并仅从CSV文件的某些列和行中提取某些值? - WITHOUT using Pandas, how do I analyze CSV data and only extract certain values from certain columns and rows of my CSV file?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM