How to delete a first and second line in each cell of column in csv

Question:

I didnt find solution for it, so maybe someone can help me

I have an csv file and it has "splitted_text" column, how can I delete the first and second line of text in each row?
enter image description here

Asked By: alakey09

||

Answers:

Based on the screenshot, I’m assuming that by:

delete the first and second line of text

you mean "delete the first and second element of each list contained in the splitter_text column"

In which case, you can simply apply a function along the column:

df["clean_splitted_text"] = df["splitted_text"].apply(lambda x: x[2:])

to save the cleaned output in a new column, or

df["splitted_text"] = df["splitted_text"].apply(lambda x: x[2:])

if you want to overwrite the content of that column (!)

Here, lambda x: x[2:] is a function that removes the first two elements of a list. If that list has 2 or fewer elements, then it returns the empty list: [].

Answered By: Florent MONIN
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.