Home > Back-end >  How to import CSV data in a single column dataframe?
How to import CSV data in a single column dataframe?

Time:12-04

I know where this error is coming from.

I try to df = pd.read_csv("\words.csv")

In this CSV, I have a column with each row filled with text. Sometimes in this text, I have this separator a comma ,. enter image description here

But I have practically all the possible symbols so I can't give it a good separator! (I have ; too)

The only thing that I know is that I only need 1 column. Is there a way to force the number of columns and not interpret the others "separators"?

CodePudding user response:

Since you are aiming to have one column, one way to achieve this goal is to use a newline \n as a separator like so:

import pandas as pd

df = pd.read_csv("\words.csv", sep="\n")

Since there will always be one line per row it is bound to always detect one column.

  • Related