-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
API design discussion #1844
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
In [1]: import pandas
In [2]: import numpy as np
In [3]: a = [1,0,3,5]
In [4]: b = [2,4,6,8]
In [5]: kk = pandas.DataFrame({'a': a, 'b': b})
In [6]: np.array(b) / np.array(a)
Out[6]: array([2, 0, 2, 1])
In [7]: kk['c'] = kk.b / kk.a
In [8]: kk
Out[8]:
a b c
0 1 2 2
1 0 4 0
2 3 6 2
3 5 8 1
In [9]: np.seterr(divide='raise')
Out[9]: {'divide': 'ignore', 'invalid': 'ignore', 'over': 'ignore', 'under': 'ignore'}
In [10]: kk['c'] = kk.b / kk.a
---------------------------------------------------------------------------
FloatingPointError Traceback (most recent call last)
...
FloatingPointError: divide by zero encountered in divide
In [12]: 8 / 5
Out[12]: 1 |
What you are asking for is Python3-like behavior. To get this, you need to do
|
thanks.. ------------------ 原始邮件 ------------------ What you are asking for is Python3-like behavior. To get this, you need to do from future import division: |
Hi, Wes or other Pandas guys, I strongly suggest to let Pandas treat dataframe index as the same as the common columns (modify the underground structure or add syntax sugar to wrap it) . As it will lower the learning curve and simplify the syntax. I can 'df.col_name' to get the column data, but I can't 'df.index_name' to get the index data , I can 'df[df[col_name]==0]' to filter/query on the common column, but I can not do that on index (yes, there is index-type filter/query functions, but it is different command) , and more ........ So in order to filter/query/aggregate/apply/.. with index, I have to 'reset_index'->filter/query/aggregate/apply/...->'set_index'.. So there exists two set of function to slice/query/..., one for common columns, one for index (and what's worse, we have 'multilevel index' and 'single level index', the syntax to deal with them seems to be different too). In my understanding, index is a special column, thought it is special, it should also be a column. So the function apply to common columns should be able to apply to index as well. I quite familiar with SQL. SQL database has 'key', and the way to deal with 'key' is same as common columns, so you can use 'select' in a unified way. I want to use Python to develop a business tool and need a '2D-matrix' datatype which Python/numpy/dict_of_dict can not handle it simply & elegantly. So I found Pandas. But Pandas costs me a lot of time & effort to find/know/diffirenciate its philosophy/function on index and columns. Stackoverflow can prove that .. I am a Pandas newbie and I might be wrong or mis-use the terms, but the 'newbie' role gives me a valuable opportunity to experience the learning curve of Pandas as a common end user. So again, can Pandas unifiy the function to process (slice/filter/query/aggregate/apply..) index and columns ? Thanks, |
pandas defaults true div since 0.14 IIRC. The other issue mentioned is detailed in several issues. |
kk=DataFrame({'a':[1,0,3,5],'b':[2,4,6,8]})
kk['c']=kk.b/kk.a
Two issues:
(1) I don't think kk[1,'c']=0 is a suitable answer
(2) I don't think kk[3,'c']=1 is a suitable answer, it should be 1.6
while kk['c']=1.0*kk.b/kk.a give an OK answer
So pls treat 'int/int' to 'float/float', for current 'int/int' treatment will cause difficult checking error
The text was updated successfully, but these errors were encountered: