Question: I want to use the data written in a text file with some headers. The file looks like this:

```
#Fruit list
#Prices from different vendors
   Pineapple    4.49   4.29   5.19
   Apple        1.99   1.89   2.19
   Banana       1.99   1.99   1.79
   Kiwi         2.99   2.99   2.99

```

I want to save this table into an array. So far I tried:

```
def fruits():
    items = []
    with open('prices.txt', 'r') as data:
        for line in data.readlines()[2:]:   #Header is always 2 lines 
            items.append(line.strip())
            species = np.array(items)
        return species

```

This returns a 0-D array, while I'm expecting a 2D array. Then I tried removing the append line (which seems unnecessary to begin with) and tried:

```
def fruits():
    items = []
    with open('prices.txt', 'r') as data:
        for line in data.readlines()[2:]:
            species = np.array(line)
        return species

```

But then this returns only the last line. It has to be a really easy fix, but I'm puzzled, especially with the second attempt.

Answer: 
If you are open to pandas and numpy then:

```
import pandas as pd
import numpy

df=pd.read_csv("Filename",index_col=0)
df.to_numpy()
df.to_records() #if index is needed too

```

should give you the required array form of data

**Example:**
Given this file: <https://file.io/5mc5MGnh0pZN>

I wrote the following to read it:
[![enter image description here](https://i.stack.imgur.com/aTEtE.png)](https://i.stack.imgur.com/aTEtE.png)

And then converted df to numpy array:

[![enter image description here](https://i.stack.imgur.com/iTklw.png)](https://i.stack.imgur.com/iTklw.png)
While @JALO - JusAnotherLivngOrgani's answer works, I'd also like to add an alternative which uses just numpy:

```
    fruits = []
    with open('File.txt') as data:
        for line in data.readlines()[2:]: #Skipping the 2 line header
            fruits.append(line)
        string = [i for item in fruits for i in item.split()] # Gives a 1D list array.
        string = np.array(string).reshape(-1,4) # Converts the list array into 2D numpy array.

```

The file is always 4 columns, but the number of rows vary, so '-1' deals with it.