Python Forum
paragraphs in textfile not detected
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
paragraphs in textfile not detected
#1
Hi!


i have a problem that i cant solve by myself. I wanna read-in a big textfile (>300mb) as a df. Die File consists of coordinates, that are seperated by \t tabs. There are 4,000 columns and 5,000 rows.

When I read this file in, python only creats one big column with 20,000 entrys, so the dimonesion is 20,000 x 1.

I don't get it as there must obviously be \n-paragraphs in the textfile.

Can someone help me please?
Reply
#2
At first I thought something is going wrong with interpreting the end-of-line character(s), but then you would have one big row.
Instead you are telling you get one big column. In that case something is going wrong with the interpretation of the tab character.

Without more information it is hard to say more about this. I suggest you show us the sample of the code reading the file and producing the column.
Reply
#3
Maybe you can use the following code to create a (numpy) array?

import pandas as pd

MyFile = 'file.txt'
MyResults = pd.read_csv(PATH + '/' + MyFile, header = None, delimiter = '	')
MyArray = pd.DataFrame.to_numpy(MyResults)
Reply
#4
Please, show us your code as well as sample data (only few lines). Obviously, if it is tab-delimited file you need to specify this because the default separator in DataFrame constructor is comma.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyTorch] no CUDA-capable device is detected constantin01 0 3,317 Apr-17-2020, 05:50 AM
Last Post: constantin01

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020