Arrays 在python中逐行读取.dat文件

Arrays 在python中逐行读取.dat文件,arrays,python-3.x,Arrays,Python 3.x,我试图读取python中的*.dat文件,而*.dat文件中的数据如下所示 1 275 2 264 3 256 275 4 194 5 38 218 6 98 7 10 255 8 157 186 9 210 261 10 141 11 45 130 它基本上有三列,所以有没有办法逐行读取它们,或者逐列读取它们并将它们存储到三个不同的数组中 在回答这个问题之前,我想指出,在堆栈溢出中,您不应该问这些问题。这个问题可以通过简单的谷歌搜

我试图读取python中的
*.dat
文件,而
*.dat
文件中的数据如下所示

1   275 
2   264 
3   256 275 
4   194 
5   38 218 
6   98 
7   10 255 
8   157 186 
9   210 261 
10  141 
11  45 130 

它基本上有三列,所以有没有办法逐行读取它们,或者逐列读取它们并将它们存储到三个不同的数组中

在回答这个问题之前,我想指出,在堆栈溢出中,您不应该问这些问题。这个问题可以通过简单的谷歌搜索和快速浏览任何机器学习库的文档或类似medium的网站上的简单教程来回答。当你用尽了所有最基本的方法,如谷歌搜索或阅读图书馆的文档时,堆栈溢出就是一个好去处。这种在求助于其他程序员之前用尽所有可能途径的习惯从长远来看会帮助你成为一名更好的程序员

就我个人而言,我要做的是将文件转换成一个数据友好的文件,如.csv或.xlsx,然后使用通用的机器学习库,以便能够解析数据

例如:(文件名为“data.csv”)

然后,逐行解析并将其放入数组的相关代码如下:

import pandas as pd 

#gets the path - tells the code where to look for said piece of data 
path = r"data.csv"

#creates a dataframe from the information in the path (your .csv file)
df = pd.read_csv(path)

#extract glucose column information and store it in a dataframe
glu_df = df["Glucose"]

#take the information from the dataframe and then store it in an array
glu_list = glu_df.values
让我用谷歌搜索一下:“python逐行读取文件”;所以,这不是免费的编码服务——你至少要自己尝试一下。这个链接可以帮助你
import pandas as pd 

#gets the path - tells the code where to look for said piece of data 
path = r"data.csv"

#creates a dataframe from the information in the path (your .csv file)
df = pd.read_csv(path)

#extract glucose column information and store it in a dataframe
glu_df = df["Glucose"]

#take the information from the dataframe and then store it in an array
glu_list = glu_df.values