-2

I am reading in a csv file locally.The sep for the data is "|", so I specify pd.read_csv(repo, sep="|"). The data loads.

However, when I examine the data, any time there is a comma in the first feature, all of that row’s data is squished into that first feature. My guess is that pandas is still seeing ‘,’ as the sep.

import pandas as pd

df = pd.read_csv(repo, sep="|", names=cols, encoding="latin-1")

df.iloc[10:15, ::]

Is there any way to handle this in pandas, or will I have to break out excel and replace the data from there?

11
  • 3
    Please provide a minimal reproducible example of your data. It is difficult to help you without it. Commented Dec 6, 2024 at 16:10
  • MRE has been added. Commented Dec 6, 2024 at 16:15
  • Can you display a few lines of your csv? Commented Dec 6, 2024 at 16:30
  • 1
    @plotmaster473 this is not a MRE. What is gs://minimum-reproduceable-2152532/item.csv supposed to be? We can't access this URI. Please read How to make good reproducible pandas examples. Commented Dec 6, 2024 at 17:25
  • An MRE would include the item.csv content with the minimal lines and columns needed to reproduce the problem, such as the header (if any) and at least a couple lines of data such as one that reads correctly and one that causes the problem. The code should be copy/paste/run without changes to reproduce the issue for readers, which means including the import statements and print statements to show the problem. Commented Dec 6, 2024 at 17:50

1 Answer 1

0

Got it; had to add the "quotechar" parameter to pd.read_csv().

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.