I want to read a csv file with following structure:
1 file, 13 insertions, 23 deletions
1 file, 43 deletions
2 file, 7 insertions
4 file, 13 insertions, 45 deletions
I would like to get a Dataframe, which should look following:
file insertions deletions
1 13 23
1 0 43
1 7 0
4 13 45
Is there a good way to do this?
You can read your file, split the values with
extractall(orsplit), thenpivot:NB. to use
split, replace.str.extract(r'(\d+) *(.*)')with.str.split(' +', n=1, expand=True).Output:
Variant with
unstackto keep the original order of columns:Output:
NB. I just realized that the output with
unstackis incorrect when usingsort=Falsewhich seems to be a bug.