-
-
Notifications
You must be signed in to change notification settings - Fork 18.3k
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
ValueError when trying to compute Quantile #14357
Comments
Can you please make this a fully reproducible example with dummy data? |
I have tracked this error down to there being NaN values in some, but not all, of the columns for a row (2 out of 10 in this case). I then tried to compute the quartile of that DF and pandas did not like this. My solution is to plug the NaN values with 0. |
Edited in a reproducible example. Hard to say for sure, but maybe related to 4de83d2 It's definitely related to a (float) block having some cols with missing values: In [11]: df = pd.DataFrame(np.random.randint(0, 10, size=(10, 2)))
In [13]: df.iloc[1, 1] = np.nan
In [14]: df.quantile(.5)
Out[14]:
0 4.5
1 7.0
Name: 0.5, dtype: float64 and In [15]: df = pd.DataFrame(np.random.randn(10, 2))
In [17]: df.iloc[0, :] = np.nan
In [18]: df.quantile(.5)
Out[18]:
0 0.347815
1 0.072105
Name: 0.5, dtype: float64 both work |
|
@Rubyj you'll have to show a complete end-to-end reproducible example. This was a bug in 0.18.1 but is correct in 0.19.0. |
@jreback the problem seems to be a DataFrame with a FloatBloack that has at least 1 col with no missing values and at least 1 col with some missing values (see my edit at the top of the OP) |
@TomAugspurger provided a reproducible example for me in my original post and added the labels that you removed. Not sure if you saw that. Thank you Tom 👍 |
@TomAugspurger your example works, I see that you changed the top of post. thanks. |
so in this case, the individual dims needs to be iterated (corresponding with the columns). with the quantiling then combined, rather than doing this all at once. numpy doesn't handle the nans in the quantiling. |
original post follows
I have a simple dataframe that I created as follows:
df[df['Week of'] == week]
where
week
is a week name I'm filtering byI have been taking the quartile values of this dataframe as follows:
df[df['Week of'] == week].quantile(.25)
However since the update to Pandas 0.19 I am receiving the error (this code worked fine before):
values = values.reshape(result_shape)
ValueError: total size of new array must be unchanged
The text was updated successfully, but these errors were encountered: