0

I want to make a dataframe of this txt file.

I tried changing delimiters or using multiple seperators or quoting csv.QUOTE_NONE, but can't read this file. please help.

df = pd.read_csv('../sort.txt', delimiter=',', header=None, quoting=csv.QUOTE_NONE, encoding='utf-8')
df

file: https://github.com/absingh22/read_csv

2 Answers2

-1

This is due to the .txt format file. Note that the number of separators , is not the same on each row. You can add the names parameter on the read_csv():

url = 'https://raw.githubusercontent.com/absingh22/read_csv/main/sort.txt'
df = pd.read_csv(url,sep=',',names=[0,1,2,3,4,5,6],header=None)
arico97
  • 1
  • 2
-1

Try this:

import pandas as pd

df = pd.read_csv('../sort.txt', header=None, quotechar='"')
print(df)

I think the issue is that th newlines within the double quotes which make pd.read_csv interpret them as new rows. So now parsing the file is correct, treating commas inside double quotes as part of the field rather than as delimiters.

Ezio
  • 19
  • 5