0

I am scraping some data from a website. I have names, and prices lists from different pages. I want to stack two lists first, then an array contains all data in rows for each page. However, np.insert gives the following error:

'ValueError: could not convert string to float'.

Here is the code

import numpy as np

finallist = []
...
for c in range(0, 10)
    narr = np.array(names)
    parr = np.array(prices)

    nparr = np.array(np.column_stack((narr, parr)))

    finallist = np.insert(finallist, c, nparr)

What I want to accomplish is the following.

finallist =  [[[name1, price1], [name2, price3], ...] # from page one
               [name1, price1], [name2, price3], ...] # from page two
               ...                                  ] # from page x

So that I will be able reach all data.

NaeiKinDus
  • 730
  • 20
  • 30
ekardon
  • 13
  • 8
  • Try setting dtype implicitly when creating arrays – Piotr Kamoda Feb 17 '17 at 10:11
  • How exactly can I do that? – ekardon Feb 17 '17 at 10:16
  • If it is as following. Then it does not work. narr = np.array(names, dtype=str) – ekardon Feb 17 '17 at 10:22
  • Possible duplicate of [NumPy array/matrix of mixed types](http://stackoverflow.com/questions/24832715/numpy-array-matrix-of-mixed-types) – MB-F Feb 17 '17 at 10:26
  • If you want to work with data like that you might want to try using `pandas`. – Khris Feb 17 '17 at 10:28
  • how about `finallist = np.insert(finallist, str(c), nparr)`? – Piotr Kamoda Feb 17 '17 at 10:34
  • No that gives more errors. I have amanged to solve the problem. I need to change `finallist=[]` into finallist=[''], so that array defined as string array. However I got another error on this line: `finallist = np.insert(finallist, c, nparr)`. It says conflicting shapes. – ekardon Feb 17 '17 at 11:37

0 Answers0