+3 votes
in Programming Languages by (17.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

0 votes
by (28.9k points)

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