Issue
I am trying to split a csv file in python . But some of the value(in one cell) has comma in it . But the function is splitting it as well thus giving me more columns than expected.
Following is my code :
data = open('FInal_epm-00000-of-00001').read()
lines_of_data = data.splitlines()
tmp = []
for i in range(len(lines_of_data)):
tmp.append(re.split('\',|, ',lines_of_data[i]))
Following is the sample input :
['string_value', 'string_value', int_value, float_value, 'string_val, string_val']
Ideal Output:
row 1 :string_value, string_value, int_value, float_value, 'string_val, string_val'
Output i am getting:
row 1 : string_value, string_value, int_value, float_value, string_val, string_val
Solution
Use the csv library. It will take care of all of that for you!
Answered By - zerecees
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.