Home > Mobile >  What is the correct way to import data from a link?
What is the correct way to import data from a link?

Time:12-06

I'm working with the xpress library due to a project I'm developing. As I have to use some official data, here is how I'm trying to retrive it:

import xpress as xp
import numpy as np
import pandas as pd

agents_assining = xp.problem()

url_X = 'https://github.com/DemeulemeesterT/GOSMI/blob/main/Benchmark instances arXiv 03_01_2021/50 agents - 50 objects/Data50_50_10_P.txt'
X = pd.read_csv(url_X,index_col=None, skiprows=4,dtype=np.object, engine='python',header=None)

But everytime I run it I get the error:

pandas.errors.ParserError: Expected 1 fields in line 457, saw 367

I'm quite sure the mistake is all in the function I'm using to read the file in the url. It says it is a .txt but if I use pd.read_table the error displayed is basically the same, so I'm a bit confused over the correct method to use here. The dataframe needs no labelling by rows or columns.

Edit: adding

error_bad_lines = False

resolves the problem but another one rasises up. The matrix I'm expecting should have 50 rows, but once called it says there are 1320 which is quite stunning. What is going on?

CodePudding user response:

First use the raw option from github before reading the file. It will give the link of the raw version of this file. Then you can read the file by specifying an Seperator.

url='https://raw.githubusercontent.com/DemeulemeesterT/GOSMI/main/Benchmark instances arXiv 03_01_2021/50 agents - 50 objects/Data50_50_10_P.txt'
df=pd.read_csv(url,header=None,skiprows=4,sep=r"\s ")

'''
|    |   0 |      1 |      2 |      3 |      4 |      5 |      6 |   7 |   8 |   9 |   10 |     11 |   12 |     13 |     14 |     15 |   16 |     17 |     18 |   19 |     20 |   21 |   22 |     23 |     24 |   25 |     26 |     27 |     28 |     29 |   30 |   31 |   32 |     33 |     34 |     35 |     36 |     37 |   38 |     39 |   40 |     41 |     42 |     43 |     44 |    45 |   46 |   47 |   48 |     49 |
|---:|----:|-------:|-------:|-------:|-------:|-------:|-------:|----:|----:|----:|-----:|-------:|-----:|-------:|-------:|-------:|-----:|-------:|-------:|-----:|-------:|-----:|-----:|-------:|-------:|-----:|-------:|-------:|-------:|-------:|-----:|-----:|-----:|-------:|-------:|-------:|-------:|-------:|-----:|-------:|-----:|-------:|-------:|-------:|-------:|------:|-----:|-----:|-----:|-------:|
|  0 |   0 | 0.5018 | 0      | 0      | 0      | 0      | 0      |   0 |   0 |   0 |    0 | 0      |    0 | 0      | 0      | 0      |    0 | 0      | 0      |    0 | 0      |    0 |    0 | 0      | 0      |    0 | 0      | 0      | 0      | 0      |    0 |    0 |    0 | 0      | 0      | 0      | 0      | 0.0849 |    0 | 0      |    0 | 0      | 0      | 0      | 0      | 0     |    0 |    0 |    0 | 0      |
|  1 |   0 | 0      | 0      | 0      | 0      | 0      | 0      |   0 |   0 |   0 |    0 | 0.1473 |    0 | 0      | 0      | 0      |    0 | 0      | 0      |    0 | 0.0191 |    0 |    0 | 0      | 0      |    0 | 0      | 0      | 0      | 0      |    0 |    0 |    0 | 0      | 0      | 0.4581 | 0      | 0      |    0 | 0      |    0 | 0      | 0      | 0      | 0      | 0     |    0 |    0 |    0 | 0      |
|  2 |   0 | 0.4982 | 0      | 0      | 0      | 0      | 0      |   0 |   0 |   0 |    0 | 0      |    0 | 0      | 0.1269 | 0      |    0 | 0      | 0      |    0 | 0      |    0 |    0 | 0      | 0      |    0 | 0      | 0      | 0      | 0      |    0 |    0 |    0 | 0      | 0      | 0      | 0      | 0      |    0 | 0      |    0 | 0      | 0      | 0      | 0      | 0     |    0 |    0 |    0 | 0      |
|  3 |   0 | 0      | 0      | 0      | 0      | 0      | 0      |   0 |   0 |   0 |    0 | 0      |    0 | 0      | 0      | 0      |    0 | 0      | 0      |    0 | 0      |    1 |    0 | 0      | 0      |    0 | 0      | 0      | 0      | 0      |    0 |    0 |    0 | 0      | 0      | 0      | 0      | 0      |    0 | 0      |    0 | 0      | 0      | 0      | 0      | 0     |    0 |    0 |    0 | 0      |
|  4 |   0 | 0      | 0      | 0      | 0      | 0      | 0      |   0 |   0 |   0 |    0 | 0      |    0 | 0.4382 | 0      | 0      |    0 | 0      | 0      |    0 | 0.0205 |    0 |    0 | 0      | 0      |    0 | 0      | 0      | 0      | 0      |    0 |    0 |    0 | 0      | 0      | 0      | 0      | 0      |    0 | 0      |    0 | 0      | 0      | 0      | 0      | 0     |    0 |    0 |    0 | 0      |
|  5 |   0 | 0      | 0      | 0      | 0      | 0      | 0      |   0 |   0 |   0 |    0 | 0      |    0 | 0      | 0.6513 | 0      |    0 | 0      | 0      |    0 | 0      |    0 |    0 | 0      | 0      |    0 | 0      | 0      | 0      | 0      |    0 |    0 |    0 | 0      | 0      | 0      | 0      | 0      |    0 | 0      |    0 | 0      | 0      | 0      | 0      | 0     |    0 |    0 |    0 | 0      |
|  6 |   0 | 0      | 0      | 0      | 0      | 0      | 0      |   0 |   0 |   0 |    0 | 0      |    0 | 0.4474 | 0      | 0      |    0 | 0      | 0      |    0 | 0      |    0 |    0 | 0      | 0      |    0 | 0      | 0      | 0      | 0      |    0 |    0 |    0 | 0      | 0      | 0      | 0      | 0      |    0 | 0      |    0 | 0      | 0      | 0      | 0      | 0     |    0 |    0 |    0 | 0      |
|  7 |   0 | 0      | 0      | 0      | 0      | 0      | 0      |   0 |   0 |   0 |    0 | 0.6037 |    0 | 0      | 0      | 0      |    0 | 0      | 0      |    0 | 0      |    0 |    0 | 0      | 0      |    0 | 0      | 0      | 0      | 0      |    0 |    0 |    0 | 0      | 0      | 0      | 0      | 0      |    0 | 0      |    0 | 0.0654 | 0      | 0      | 0      | 0     |    0 |    0 |    0 | 0      |
|  8 |   0 | 0      | 0      | 0      | 0      | 0      | 0      |   0 |   0 |   0 |    0 | 0      |    0 | 0      | 0      | 0      |    0 | 0      | 0      |    1 | 0      |    0 |    0 | 0      | 0      |    0 | 0      | 0      | 0      | 0      |    0 |    0 |    0 | 0      | 0      | 0      | 0      | 0      |    0 | 0      |    0 | 0      | 0      | 0      | 0      | 0     |    0 |    0 |    0 | 0      |
|  9 |   1 | 0      | 0      | 0      | 0      | 0      | 0      |   0 |   0 |   0 |    0 | 0      |    0 | 0      | 0      | 0      |    0 | 0      | 0      |    0 | 0      |    0 |    0 | 0      | 0      |    0 | 0      | 0      | 0      | 0      |    0 |    0 |    0 | 0      | 0      | 0      | 0      | 0      |    0 | 0      |    0 | 0      | 0      | 0      | 0      | 0     |    0 |    0 |    0 | 0      |
| 10 |   0 | 0      | 0      | 0      | 0      | 0      | 0      |   0 |   0 |   0 |    0 | 0      |    0 | 0      | 0      | 0      |    0 | 0      | 0      |    0 | 0      |    0 |    0 | 0      | 0      |    0 | 0      | 0      | 0      | 0.254  |    0 |    0 |    0 | 0      | 0      | 0      | 0      | 0      |    0 | 0      |    0 | 0      | 0      | 0      | 0      | 0     |    0 |    0 |    0 | 0      |
| 11 |   0 | 0      | 0.6694 | 0      | 0      | 0      | 0      |   0 |   0 |   0 |    0 | 0      |    0 | 0      | 0      | 0      |    0 | 0      | 0      |    0 | 0      |    0 |    0 | 0      | 0      |    0 | 0      | 0      | 0      | 0      |    0 |    0 |    0 | 0      | 0      | 0      | 0      | 0      |    0 | 0      |    0 | 0      | 0      | 0.3306 | 0      | 0     |    0 |    0 |    0 | 0      |
| 12 |   0 | 0      | 0      | 0.4987 | 0      | 0      | 0      |   0 |   0 |   0 |    0 | 0      |    0 | 0      | 0      | 0      |    0 | 0      | 0      |    0 | 0      |    0 |    0 | 0      | 0      |    0 | 0      | 0      | 0      | 0      |    0 |    0 |    0 | 0      | 0      | 0      | 0      | 0      |    0 | 0      |    0 | 0      | 0      | 0      | 0      | 0     |    0 |    0 |    0 | 0      |
| 13 |   0 | 0      | 0      | 0      | 0      | 0      | 0      |   0 |   0 |   0 |    0 | 0      |    0 | 0      | 0      | 0      |    0 | 0      | 0      |    0 | 0      |    0 |    0 | 0      | 0      |    0 | 0.3429 | 0      | 0      | 0      |    0 |    0 |    0 | 0      | 0      | 0.4574 | 0      | 0      |    0 | 0      |    0 | 0      | 0      | 0      | 0.0946 | 0     |    0 |    0 |    0 | 0      |
| 14 |   0 | 0      | 0      | 0      | 0      | 0      | 0      |   0 |   0 |   0 |    0 | 0      |    0 | 0      | 0      | 0      |    0 | 0      | 0      |    0 | 0      |    0 |    0 | 0      | 0      |    0 | 0      | 0      | 0      | 0      |    0 |    0 |    0 | 0      | 0      | 0      | 0      | 0      |    0 | 0      |    0 | 0      | 0      | 0.3382 | 0      | 0     |    0 |    0 |    0 | 0      |
| 15 |   0 | 0      | 0      | 0      | 0      | 0      | 0.5481 |   0 |   0 |   0 |    0 | 0      |    0 | 0      | 0      | 0      |    0 | 0      | 0      |    0 | 0      |    0 |    0 | 0      | 0      |    0 | 0      | 0      | 0      | 0      |    0 |    0 |    0 | 0      | 0      | 0      | 0      | 0      |    0 | 0      |    0 | 0      | 0      | 0      | 0.4519 | 0     |    0 |    0 |    0 | 0      |
| 16 |   0 | 0      | 0      | 0      | 0      | 0      | 0      |   0 |   0 |   0 |    0 | 0      |    0 | 0      | 0      | 0      |    0 | 0      | 0      |    0 | 0      |    0 |    0 | 1      | 0      |    0 | 0      | 0      | 0      | 0      |    0 |    0 |    0 | 0      | 0      | 0      | 0      | 0      |    0 | 0      |    0 | 0      | 0      | 0      | 0      | 0     |    0 |    0 |    0 | 0      |
| 17 |   0 | 0      | 0      | 0.5013 | 0      | 0      | 0      |   0 |   0 |   0 |    0 | 0      |    0 | 0      | 0      | 0      |    0 | 0      | 0      |    0 | 0      |    0 |    0 | 0      | 0      |    0 | 0      | 0      | 0      | 0      |    0 |    0 |    0 | 0      | 0      | 0.0845 | 0      | 0      |    0 | 0.0926 |    0 | 0      | 0      | 0      | 0      | 0     |    0 |    0 |    0 | 0      |
| 18 |   0 | 0      | 0      | 0      | 0      | 0.8278 | 0      |   0 |   0 |   0 |    0 | 0      |    0 | 0      | 0      | 0      |    0 | 0      | 0      |    0 | 0      |    0 |    0 | 0      | 0      |    0 | 0      | 0      | 0      | 0      |    0 |    0 |    0 | 0      | 0      | 0      | 0      | 0      |    0 | 0      |    0 | 0      | 0      | 0      | 0      | 0     |    0 |    0 |    0 | 0      |
| 19 |   0 | 0      | 0      | 0      | 0      | 0      | 0      |   0 |   0 |   0 |    0 | 0      |    0 | 0      | 0      | 0      |    0 | 0      | 0      |    0 | 0      |    0 |    0 | 0      | 0      |    0 | 0      | 0      | 0      | 0      |    0 |    0 |    0 | 0      | 0      | 0      | 0      | 0.4249 |    0 | 0.1678 |    0 | 0      | 0      | 0      | 0      | 0     |    0 |    0 |    0 | 0      |
| 20 |   0 | 0      | 0      | 0      | 0      | 0      | 0      |   0 |   0 |   0 |    0 | 0.6086 |    0 | 0.0342 | 0      | 0      |    0 | 0      | 0      |    0 | 0      |    0 |    0 | 0      | 0      |    0 | 0      | 0      | 0.03   | 0      |    0 |    0 |    0 | 0      | 0      | 0      | 0.308  | 0      |    0 | 0      |    0 | 0      | 0      | 0      | 0      | 0     |    0 |    0 |    0 | 0      |
| 21 |   0 | 0      | 0      | 0      | 0      | 0      | 0      |   0 |   0 |   0 |    0 | 0      |    0 | 0      | 0      | 0      |    0 | 0      | 0      |    0 | 0.1593 |    0 |    0 | 0      | 0      |    0 | 0      | 0      | 0      | 0      |    0 |    0 |    0 | 0.8407 | 0      | 0      | 0      | 0      |    0 | 0      |    0 | 0      | 0      | 0      | 0      | 0     |    0 |    0 |    0 | 0      |
| 22 |   0 | 0      | 0      | 0      | 0      | 0      | 0      |   0 |   0 |   0 |    0 | 0      |    1 | 0      | 0      | 0      |    0 | 0      | 0      |    0 | 0      |    0 |    0 | 0      | 0      |    0 | 0      | 0      | 0      | 0      |    0 |    0 |    0 | 0      | 0      | 0      | 0      | 0      |    0 | 0      |    0 | 0      | 0      | 0      | 0      | 0     |    0 |    0 |    0 | 0      |
| 23 |   0 | 0      | 0      | 0      | 0      | 0      | 0      |   0 |   0 |   0 |    0 | 0      |    0 | 0      | 0      | 0      |    0 | 0      | 0      |    0 | 0      |    0 |    0 | 0      | 0      |    0 | 0      | 0      | 0      | 0      |    0 |    0 |    0 | 0      | 0      | 0      | 0.2161 | 0      |    0 | 0.7396 |    0 | 0      | 0.0443 | 0      | 0      | 0     |    0 |    0 |    0 | 0      |
| 24 |   0 | 0      | 0      | 0      | 0      | 0      | 0      |   0 |   0 |   0 |    0 | 0      |    0 | 0      | 0.2218 | 0      |    0 | 0      | 0      |    0 | 0      |    0 |    0 | 0      | 0      |    0 | 0      | 0      | 0      | 0      |    0 |    0 |    0 | 0      | 0      | 0      | 0      | 0      |    0 | 0      |    0 | 0      | 0      | 0.3308 | 0      | 0     |    0 |    0 |    0 | 0      |
| 25 |   0 | 0      | 0      | 0      | 0.8408 | 0      | 0      |   0 |   0 |   0 |    0 | 0      |    0 | 0      | 0      | 0      |    0 | 0      | 0      |    0 | 0.1592 |    0 |    0 | 0      | 0      |    0 | 0      | 0      | 0      | 0      |    0 |    0 |    0 | 0      | 0      | 0      | 0      | 0      |    0 | 0      |    0 | 0      | 0      | 0      | 0      | 0     |    0 |    0 |    0 | 0      |
| 26 |   0 | 0      | 0      | 0      | 0      | 0      | 0      |   0 |   0 |   0 |    0 | 0      |    0 | 0      | 0      | 0      |    0 | 0      | 0      |    0 | 0.1615 |    0 |    0 | 0      | 0.5014 |    0 | 0      | 0      | 0      | 0      |    0 |    0 |    0 | 0      | 0      | 0      | 0      | 0      |    0 | 0      |    0 | 0      | 0      | 0      | 0      | 0     |    0 |    0 |    0 | 0      |
| 27 |   0 | 0      | 0      | 0      | 0      | 0      | 0      |   0 |   0 |   0 |    0 | 0      |    0 | 0      | 0      | 0      |    0 | 0      | 0      |    0 | 0.1555 |    0 |    0 | 0      | 0      |    0 | 0      | 0      | 0      | 0      |    0 |    0 |    0 | 0      | 0      | 0      | 0      | 0      |    0 | 0      |    0 | 0      | 0      | 0      | 0      | 0     |    0 |    0 |    0 | 0      |
| 28 |   0 | 0      | 0      | 0      | 0      | 0      | 0      |   0 |   0 |   1 |    0 | 0      |    0 | 0      | 0      | 0      |    0 | 0      | 0      |    0 | 0      |    0 |    0 | 0      | 0      |    0 | 0      | 0      | 0      | 0      |    0 |    0 |    0 | 0      | 0      | 0      | 0      | 0      |    0 | 0      |    0 | 0      | 0      | 0      | 0      | 0     |    0 |    0 |    0 | 0      |
| 29 |   0 | 0      | 0      | 0      | 0      | 0      | 0      |   0 |   0 |   0 |    0 | 0.0291 |    0 | 0      | 0      | 0      |    0 | 0.8133 | 0.1576 |    0 | 0      |    0 |    0 | 0      | 0      |    0 | 0      | 0      | 0      | 0      |    0 |    0 |    0 | 0      | 0      | 0      | 0      | 0      |    0 | 0      |    0 | 0      | 0      | 0      | 0      | 0     |    0 |    0 |    0 | 0      |
| 30 |   0 | 0      | 0      | 0      | 0      | 0      | 0      |   0 |   0 |   0 |    0 | 0      |    0 | 0      | 0      | 0      |    0 | 0      | 0      |    0 | 0      |    0 |    0 | 0      | 0      |    0 | 0      | 0      | 0      | 0.2465 |    0 |    0 |    0 | 0      | 0      | 0      | 0      | 0.1832 |    0 | 0      |    0 | 0      | 0      | 0      | 0      | 0     |    0 |    0 |    0 | 0      |
| 31 |   0 | 0      | 0      | 0      | 0      | 0      | 0      |   0 |   0 |   0 |    0 | 0      |    0 | 0      | 0      | 0      |    0 | 0      | 0      |    0 | 0      |    0 |    0 | 0      | 0      |    0 | 0      | 0      | 0      | 0      |    0 |    0 |    0 | 0      | 0      | 0      | 0      | 0      |    0 | 0      |    0 | 0.6532 | 0      | 0      | 0      | 0     |    0 |    0 |    0 | 0      |
| 32 |   0 | 0      | 0      | 0      | 0      | 0      | 0      |   0 |   0 |   0 |    0 | 0      |    0 | 0      | 0      | 0      |    0 | 0      | 0      |    0 | 0      |    0 |    0 | 0      | 0      |    0 | 0.4184 | 0      | 0      | 0      |    0 |    0 |    0 | 0      | 0      | 0      | 0      | 0      |    0 | 0      |    0 | 0      | 0      | 0      | 0      | 0     |    0 |    0 |    0 | 0.5002 |
| 33 |   0 | 0      | 0      | 0      | 0      | 0      | 0      |   0 |   0 |   0 |    0 | 0      |    0 | 0      | 0      | 0.5055 |    0 | 0      | 0      |    0 | 0      |    0 |    0 | 0.006  | 0      |    0 | 0      | 0      | 0.4885 | 0      |    0 |    0 |    0 | 0      | 0      | 0      | 0      | 0      |    0 | 0      |    0 | 0      | 0      | 0      | 0      | 0     |    0 |    0 |    0 | 0      |
| 34 |   0 | 0      | 0      | 0      | 0      | 0      | 0      |   0 |   0 |   0 |    0 | 0      |    0 | 0.0802 | 0      | 0      |    0 | 0      | 0      |    0 | 0      |    0 |    0 | 0      | 0      |    0 | 0      | 0      | 0      | 0      |    0 |    0 |    0 | 0      | 0      | 0      | 0      | 0.0412 |    0 | 0      |    0 | 0      | 0      | 0      | 0      | 0     |    0 |    0 |    0 | 0.4998 |
| 35 |   0 | 0      | 1      | 0      | 0      | 0      | 0      |   0 |   0 |   0 |    0 | 0      |    0 | 0      | 0      | 0      |    0 | 0      | 0      |    0 | 0      |    0 |    0 | 0      | 0      |    0 | 0      | 0      | 0      | 0      |    0 |    0 |    0 | 0      | 0      | 0      | 0      | 0      |    0 | 0      |    0 | 0      | 0      | 0      | 0      | 0     |    0 |    0 |    0 | 0      |
| 36 |   0 | 0      | 0      | 0      | 0      | 0      | 0      |   0 |   0 |   0 |    0 | 0      |    0 | 0      | 0      | 0      |    0 | 0      | 0      |    0 | 0      |    0 |    0 | 0      | 0      |    0 | 0      | 0      | 0      | 0.2546 |    0 |    0 |    0 | 0      | 0      | 0      | 0      | 0      |    0 | 0      |    0 | 0.2814 | 0      | 0      | 0      | 0.464 |    0 |    0 |    0 | 0      |
| 37 |   0 | 0      | 0      | 0      | 0      | 0      | 0      |   0 |   0 |   0 |    0 | 0      |    0 | 0      | 0      | 0      |    0 | 0      | 0      |    0 | 0.1675 |    0 |    0 | 0      | 0      |    0 | 0      | 0      | 0      | 0      |    0 |    0 |    0 | 0      | 0      | 0      | 0      | 0      |    0 | 0      |    0 | 0      | 0      | 0      | 0      | 0     |    0 |    0 |    0 | 0      |
| 38 |   0 | 0      | 0      | 0      | 0      | 0      | 0      |   0 |   0 |   0 |    0 | 0      |    0 | 0      | 0      | 0      |    0 | 0      | 0      |    0 | 0      |    0 |    0 | 0      | 0      |    0 | 0      | 0      | 0      | 0      |    0 |    0 |    0 | 0      | 0      | 0      | 0      | 0      |    0 | 0      |    0 | 0      | 0      | 0      | 0.4535 | 0     |    0 |    0 |    0 | 0      |
| 39 |   0 | 0      | 0      | 0      | 0      | 0      | 0      |   0 |   0 |   0 |    0 | 0      |    0 | 0      | 0      | 0      |    0 | 0      | 0      |    0 | 0.1574 |    0 |    0 | 0      | 0      |    0 | 0      | 0      | 0      | 0      |    0 |    0 |    0 | 0      | 0      | 0      | 0      | 0      |    0 | 0      |    0 | 0      | 0      | 0      | 0      | 0     |    0 |    0 |    0 | 0      |
| 40 |   0 | 0      | 0      | 0      | 0      | 0      | 0      |   0 |   0 |   0 |    0 | 0      |    0 | 0      | 0      | 0      |    0 | 0      | 0      |    0 | 0      |    0 |    0 | 0.0397 | 0      |    0 | 0.9599 | 0      | 0      | 0      |    0 |    0 |    0 | 0      | 0      | 0      | 0      | 0      |    0 | 0      |    0 | 0      | 0      | 0.0004 | 0      | 0     |    0 |    0 |    0 | 0      |
| 41 |   0 | 0      | 0      | 0      | 0      | 0      | 0      |   0 |   0 |   0 |    0 | 0      |    0 | 0      | 0      | 0      |    0 | 0      | 0      |    0 | 0      |    0 |    0 | 0      | 0      |    0 | 0      | 0      | 0      | 0      |    0 |    0 |    0 | 0      | 0      | 0      | 0      | 0      |    1 | 0      |    0 | 0      | 0      | 0      | 0      | 0     |    0 |    0 |    0 | 0      |
| 42 |   0 | 0      | 0      | 0      | 0      | 0      | 0      |   0 |   0 |   0 |    0 | 0      |    0 | 0      | 0      | 0      |    0 | 0      | 0      |    0 | 0      |    0 |    0 | 0      | 0      |    0 | 0      | 0      | 0      | 0      |    0 |    0 |    0 | 0      | 0      | 0      | 0      | 0.4106 |    0 | 0      |    0 | 0      | 0      | 0      | 0      | 0     |    0 |    0 |    0 | 0      |
| 43 |   0 | 0      | 0      | 0      | 0      | 0      | 0      |   0 |   0 |   0 |    0 | 0      |    0 | 0      | 0      | 0      |    0 | 0      | 0      |    0 | 0      |    0 |    0 | 0      | 0      |    1 | 0      | 0      | 0      | 0      |    0 |    0 |    0 | 0      | 0      | 0      | 0      | 0      |    0 | 0      |    0 | 0      | 0      | 0      | 0      | 0     |    0 |    0 |    0 | 0      |
| 44 |   0 | 0      | 0      | 0      | 0      | 0.1722 | 0      |   0 |   0 |   0 |    0 | 0      |    0 | 0      | 0      | 0      |    0 | 0      | 0      |    0 | 0      |    0 |    0 | 0      | 0      |    0 | 0      | 0      | 0      | 0      |    0 |    0 |    0 | 0      | 0      | 0      | 0      | 0.4376 |    0 | 0      |    0 | 0      | 0      | 0      | 0      | 0     |    0 |    0 |    0 | 0      |
| 45 |   0 | 0      | 0      | 0      | 0      | 0      | 0      |   0 |   0 |   0 |    0 | 0      |    0 | 0      | 0      | 0      |    0 | 0.1867 | 0      |    0 | 0      |    0 |    0 | 0      | 0      |    0 | 0      | 0      | 0      | 0      |    0 |    0 |    0 | 0      | 0.3957 | 0      | 0      | 0.4176 |    0 | 0      |    0 | 0      | 0      | 0      | 0      | 0     |    0 |    0 |    0 | 0      |
| 46 |   0 | 0      | 0      | 0      | 0      | 0      | 0      |   0 |   0 |   0 |    0 | 0      |    0 | 0      | 0      | 0.4945 |    0 | 0      | 0      |    0 | 0      |    0 |    0 | 0      | 0      |    0 | 0      | 0.5055 | 0      | 0      |    0 |    0 |    0 | 0      | 0      | 0      | 0      | 0      |    0 | 0      |    0 | 0      | 0      | 0      | 0      | 0     |    0 |    0 |    0 | 0      |
| 47 |   1 | 0      | 0      | 0      | 0      | 0      | 0      |   0 |   0 |   0 |    0 | 0      |    0 | 0      | 0      | 0      |    0 | 0      | 0      |    0 | 0      |    0 |    0 | 0      | 0      |    0 | 0      | 0      | 0      | 0      |    0 |    0 |    0 | 0      | 0      | 0      | 0      | 0      |    0 | 0      |    0 | 0      | 0      | 0      | 0      | 0     |    0 |    0 |    0 | 0      |
| 48 |   0 | 0      | 0      | 0      | 0      | 0      | 0      |   0 |   0 |   0 |    0 | 0      |    0 | 0      | 0      | 0      |    0 | 0      | 0      |    0 | 0      |    0 |    0 | 0      | 0.381  |    0 | 0      | 0      | 0      | 0.2449 |    0 |    0 |    0 | 0      | 0      | 0      | 0      | 0      |    0 | 0      |    0 | 0      | 0      | 0      | 0      | 0     |    0 |    0 |    0 | 0      |
| 49 |   0 | 0      | 0      | 0      | 0      | 0      | 0      |   0 |   0 |   0 |    0 | 0.6113 |    0 | 0      | 0      | 0      |    0 | 0      | 0      |    0 | 0      |    0 |    0 | 0      | 0.0949 |    0 | 0      | 0      | 0      | 0      |    0 |    0 |    0 | 0      | 0      | 0      | 0      | 0      |    0 | 0      |    0 | 0      | 0      | 0      | 0      | 0     |    0 |    0 |    0 | 0      |
'''

CodePudding user response:

The file you are trying to read is a .txt file

You can read it using the following code

from urllib import request
url = 'https://raw.githubusercontent.com/DemeulemeesterT/GOSMI/main/Benchmark instances arXiv 03_01_2021/50 agents - 50 objects/Data50_50_10_P.txt'
data = request.urlopen(url).read().decode('utf-8')
print(data)

Then you transform the string into a pandas DataFrame

import pandas as pd
df = pd.DataFrame([x.split('\t') for x in data.splitlines() if x and x[0].isdigit()])

The point of the if x and x[0].isdigit() is to sanitize your data because there are some MIN = 33 at the beginning of the file

  • Related