+4 votes
in Programming Languages by (53.0k points)
I have to use data from a text file in a machine learning model. The data in the file is tab-delimited. After getting data from the file, I want to convert it into a NumPy array. How can I do this?

1 Answer

+1 vote
by (176k points)
selected by
 
Best answer

You can use the read_csv() function of Pandas to read the tab separated file. The function will return a dataframe. You can convert the dataframe into a Numpy array using either values or to_numpy().

Here is an example:

df = pd.read_csv(tab_delimited_file, sep='\t')
dataset = df.values


...