adobean
adobean

Reputation: 331

Pandas split the string in each line with "-"

I have a dataset. Each row in this dataset has vulnerability and explanation. but I just want to take the vulnerability. I want to separate each line from the part where the "-" sign is

import pandas as pd
df=pd.read_csv("dosya.csv")
print(df)

my dataset

Apache 2.x - Memory Leak;
Microsoft Internet Explorer 11 - Crash (PoC) (1)....
Apache 2.0.44 (Linux) - Remote Denial of Service.....
Chindi Server 1.0 - Denial of Service.....
Xeneo Web Server 2.2.9.0 - Denial of Service.....

Upvotes: 0

Views: 59

Answers (2)

Mehdi Golzadeh
Mehdi Golzadeh

Reputation: 2583

You can use split function and create a new column called vulnerability:

import pandas as pd
df=pd.read_csv("dosya.csv",names =['error'])

df = (
    df
    .assign(vulnerability = lambda x: x['error'].apply(lambda s: s.split(' - ')[1]))
)

Upvotes: 1

wind
wind

Reputation: 2451

You could do something like this:

import pandas as pd

df = pd.read_csv("dosya.csv", sep="-")
print(df)

Upvotes: 0

Related Questions