从字符串 python 中获取数字

Get numbers from string python

我面临以下问题。我正在尝试下载此数据集: Dataset link

这样:

data_file_url = 'http://cs.joensuu.fi/sipu/datasets/s1.txt'
D = np.array(pd.read_csv(data_file_url,header=0))
D = D[ np.random.choice(np.arange(D.shape[0]), D.shape[0], replace=False) ,:]
Dx = D[:,0:2]
Dy = D[:,2]

但它似乎以 .txt 数组格式出现。那不是真正的问题,而是字符串本身。它以这种形式出现:

[['    665845    557965']
 ['    597173    575538']
 ['    618600    551446']
 ...
 ['    650661    861267']
 ['    599647    858702']
 ['    684091    842566']]

,其中所有的数组都是一个巨大的奇怪字符串,有很多空白和两个数字,它们是坐标。我正在尝试以这种形式获取它 [123124412, 12312442]

数据集可以.txt 或.ts 格式下载。

我尝试拆分,然后转换为 int,但显然我得到的是所有数字而不是 2。

感谢您的帮助或建议!

您是否尝试过使用 pd.read_csv 的可选参数?
请尝试以下操作:
D = np.array(pd.read_csv(data_file_url,header=0,delimiter=' '))

splitted = []

for nums in D:
    first, second = nums[0].split()
    first, second = int(first), int(second)
    splitted.append([first, second])

D = np.array(splitted)