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.

7
  • Try setting dtype implicitly when creating arrays Commented Feb 17, 2017 at 10:11
  • How exactly can I do that? Commented Feb 17, 2017 at 10:16
  • If it is as following. Then it does not work. narr = np.array(names, dtype=str) Commented Feb 17, 2017 at 10:22
  • Possible duplicate of NumPy array/matrix of mixed types Commented Feb 17, 2017 at 10:26
  • If you want to work with data like that you might want to try using pandas. Commented Feb 17, 2017 at 10:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.