1
votes

Need help in importing CSV file into python.

My CSV file

0,Donc, 2 jours, je me suis rendu compte que Musikfest est le lendemain de voir dmb, quel problème. Signifie que je ne peux pas aller ...
0,Le son est définitivement gâché.Noooooo mon bb
0,Il est le mien! Haha il me suit: ') m'aime et me veut.haha.i wana vivre en Amérique annie

I want to split the above file into 2 columns

Coloumn1 ---- Coloumn2
 0 ---- Donc, 2 jours, je me suis rendu compte que Musikfest est le 
        lendemain de voir dmb, quel problème. Signifie que je ne peux pas 
        aller ...
 0 ---- Le son est définitivement gâché.Noooooo mon bb
 0 ---- Il est le mien! Haha il me suit: ') m'aime et me veut.haha.i wana 
        vivre en Amérique annie

Since my text has commas embedded and my value for the text is always the first character. Is it possible to read my CSV file with splitting first character and rest of the text?

2

2 Answers

2
votes

You can use string.split() and specify a max split of 1. By this I mean, if you just want to split the line on the first comma, then do not read the file as a CSV. Instead read it line by line and split the line using string.split(',', 1)

1
votes

You should use csv library to work with csv files: https://docs.python.org/3/library/csv.html#csv.reader

import csv


result = []

with open('test.csv') as csvfile:
    csvreader = csv.reader(csvfile)
    for row in csvreader:
        result.append((row[0], ''.join(row[1:])))

print(result)