'Pandas reads the txt file as 1 column except header

I have a txt file with following data;

"a" "b" "c" "d" "e" "f" "g" "h"
"2" "222" "0.111" "b1" "19.11" "17.96" "2.85" ""
"3" "333" "0.123" "b2" "42.79" "26.68" "2.85" ""
"4" "444" "0.105" "b3" "17.28" "16.50" "2.85" ""
"5" "555" "0.106" "b4" "18.74" "19.78" "2.88" ""
"6" "666" "0.107" "b5" "5.79" "9.93" "2.88" ""

I am trying to read file with pandas with following code;

df = pd.read_csv("test.txt",sep="\t",quotechar='"',quoting=csv.QUOTE_NONE)

When I try to get columns with room_file.columns it print this;

Index(['"uid" "raum_code" "tuerschild" "raumbezeichung" "raumflaeche" "raumumfang" "raumhoehe" "Comments"'], dtype='object')

But the df output looks just 1 column;

    "a" "b" "c" "d" "e" "f" "g" "h"
0   "2" "222" "0.111" "b1" "19.11" "17.96" "2.8...
1   "3" "333" "0.123" "b2" "42.79" ...
2   "4" "444" "0.105" "b3" "17.28" "16.50" "2...
3   "5" "555" "0.106" "b4" "18.74" "19.78" "2...
4   "6" "666" "0.107" "b5" "5.79"...

5 rows × 1 columns

But it supposed to be 5 rows × 8 columns

I already try:

Solution 1 Solution 2

And I also try like this:

df = pd.read_csv("test.txt",sep='\t',header=0)

But everything same. Can you please help to read the txt file as a dataframe.



Solution 1:[1]

i try this and it shows correct result

df = pd.read_csv("test.txt", header=0, quotechar="\"", sep=" ")

print(df.columns)
print(df.shape) 
print(df)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Amir Aref