I've read this, this and this posts but despite I don't know why quotechar
does not work at pd.read_csv()
(Python 3, pandas 0.18.0 and 0.18.1). And how could I read a dataframe like this:
"column1","column2", "column3", "column4", "column5", "column6"
"AM", 7, "1", "SD", "SD", "CR"
"AM", 8, "1,2 ,3", "PR, SD,SD", "PR ; , SD,SD", "PR , ,, SD ,SD"
"AM", 1, "2", "SD", "SD", "SD"
I want the following result:
Out[116]:
column1 column2 column3 column4 column5 column6
0 AM 7 1 SD SD CR
1 AM 8 1,2 ,3 PR, SD,SD PR ; , SD,SD PR , ,, SD,SD
2 AM 1 2 SD SD SD
Thank you!!
We can read data from a text file using read_table() in pandas. This function reads a general delimited file to a DataFrame object. This function is essentially the same as the read_csv() function but with the delimiter = '\t', instead of a comma by default.
You can use df. head() to get the first N rows in Pandas DataFrame.
To read CSV file without header, use the header parameter and set it to “None” in the read_csv() method.
Pandas doc on separators in read_csv()
:
Separators longer than 1 character and different from '\s+' will be interpreted as regular expressions, will force use of the python parsing engine and will ignore quotes in the data.
Try using this instead (sep
by default set to a comma):
pd.read_csv(file, skipinitialspace = True, quotechar = '"')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With