0

I'm really new to python and pandas so would you please help me answer this seemingly simple question? I already have an excel file containing my data, now I want to create an array containing those data in python. For example, I have data in excel that look like this:

enter image description here

I want from those data to create a matrix of the form like the python code below:

enter image description here

Actually, my data is much longer so is there any way that I can take advantage of pandas to put the data from my excel file into a matrix in python similar to the simple example above? Thank you!

Namfield
  • 43
  • 9
  • 1
    Personally I would only save the data area to a csv, load it into python using pandas, then add in the rows & column labels myself, as those can be easily copied and pasted from excel to code. When you've completed loading in the data you can use `pandas.DataFrame.to_numpy()` and `numpy.reshape` to reshape your array. Do you think your dataset is still too big for this operation? – Yellocat Mar 30 '21 at 15:27
  • 1
    [enter link description here](https://stackoverflow.com/q/48054473/14816783) can help you. – Amirhossein Mar 30 '21 at 15:30

2 Answers2

0

You can use pandas.read_excel()

In the documentation there is also some examples like:

pd.read_excel('tmp.xlsx', index_col=0)  
       Name  Value
0   string1      1
1   string2      2
2  #Comment      3
Dharman
  • 30,962
  • 25
  • 85
  • 135
0

you can put all your values into a=np.array([40,56,87,98,58,98,56,63]), then a.reshape(4,2) but in your case a.reshape(3,9). Hope you get my point.

  • 1
    However, as I said my real data is much bigger, around 200 values so I think typing all of them is not really a clever way. – Namfield Mar 30 '21 at 15:52