We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
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
I've come across a peculiar case, it has two conditions:
sample = pd.DataFrame({'date': [pd.NaT, pd.NaT, pd.NaT, pd.NaT], 'period': [1,1,1,1], 'parent_id': ['a', 'b', 'c', 'd']}) sample.apply(lambda x: {'parent_user_id': x.parent_id}, axis=1, reduce=True)
This is flawed since the output should be a series where each element is a dictionary, instead this outputs a dataframe of NaNs.
Out[40]: 0 {'parent_user_id': 'a'} 1 {'parent_user_id': 'b'} 2 {'parent_user_id': 'c'} 3 {'parent_user_id': 'd'}
Out[46]: date parent_id period 0 NaN NaN NaN 1 NaN NaN NaN 2 NaN NaN NaN 3 NaN NaN NaN
The text was updated successfully, but these errors were encountered:
Nothing to do with NaT, as this same thing happens after you fill the values
NaT
In [15]: sample.fillna(dict(date=pd.Timestamp('2017'))).apply(lambda x: {'parent_user_id': x.parent_id}, axis=1, reduce=True) ...: ...: Out[15]: date parent_id period 0 NaN NaN NaN 1 NaN NaN NaN 2 NaN NaN NaN 3 NaN NaN NaN
NaT and None might have behaved differently, if using None forced an object dtype.
None
object
This is more about the output shape inference that apply does. You'll be much better off avoiding .apply(..., axis=1) and just doing things directly:
apply
.apply(..., axis=1)
In [20]: pd.Series([{'parent_user_id': x.parent_id} for x in sample.itertuples()]) Out[20]: 0 {'parent_user_id': 'a'} 1 {'parent_user_id': 'b'} 2 {'parent_user_id': 'c'} 3 {'parent_user_id': 'd'} dtype: object
Sorry, something went wrong.
This falls under #15628
No branches or pull requests
Code Sample
I've come across a peculiar case, it has two conditions:
Problem description
This is flawed since the output should be a series where each element is a dictionary, instead this outputs a dataframe of NaNs.
Expected Output
Output
The text was updated successfully, but these errors were encountered: