Length Of Values Not Matching Length Of Index
I am doing some cryptocurrency analysis utilizing the Pandas library for Python. I have produced the following dataframe:
coin old_price current_price 0 BNBBTC 0.000949 0.000994 1 BNBETH 0.011472 0.012129 2 BNBUSDT 10.938950 9.358000 3 VENBNB 0.619480 0.635200
Then, I am attempting to compare the two columns old_price and current_price.
Upon using this line of code below:
comparison['sell'] = np.where((comparison['current_price'] >= comparison['old_price']))
I am receive an error stating:
"ValueError: Length of values does not match length of index"
To the best of my knowledge, the dataframe has the same number of data for each column. Please advise, it would be much appreciated.
np.where(condition) without the second and third optional arguments returns the array of row indexes for which the
True. This array in general is shorter than the original DataFrame (in your case, it has only one value):
np.where(comparison['current_price'] >= comparison['old_price']) #(array(),)
What you need is probably this:
comparison['sell'] = (comparison['current_price'] >= comparison['old_price']) #array([False, False, True, False], dtype=bool)
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module