I have a very dirty data that I need to read in Python. The csv file seperated with comma, but there are also some commas in the first column of my data that puts me in a tight position. Something like this:
import pandas as pd
# initialize data of lists.
data = {'reportname':['column1,column2, column3, column4',
'some...texts, are here with commas, www.facebook.com, 2000, 150',
'some-texts_again_here, www.twitter.com, 1000, 50']}
# Create DataFrame
df = pd.DataFrame(data)
However, it does not match the data in correct columns since there is comma inside some of the rows of the first column. Here is my desired data:
desired_data = {'column1':['some...texts, are here with commas', 'some-texts_again_here'],
'column2':['www.facebook.com', 'www.twitter.com'],
'column3':[2000, 1000],
'column4':[150, 50]}
# Create DataFrame
df = pd.DataFrame(desired_data)
Is there a way to read the csv file accurately?