You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The above code returns NaT values for the cohort column, but it was expected to return the minimum values for week, which in this case would be 2020-02-10/2020-02-16 for all rows.
This is expected behavior. Look at the values from df.groupby('user_id')['week'].min() by itself, they will have index given by user_id. Then when you make the assignment todf['cohort'], pandas will try to align the integer index of df with the index of the groupby results. When pandas finds no match, the null value is appropriately used.
This is the reason transform exists, and is the appropriate method to use here.
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
(optional) I have confirmed this bug exists on the master branch of pandas.
Code Sample:
Problem description
The above code returns NaT values for the
cohort
column, but it was expected to return the minimum values forweek
, which in this case would be2020-02-10/2020-02-16
for all rows.Expected Output
If we change the last line to:
We get the expected value for the cohort column, i.e.,
2020-02-10/2020-02-16
.Output of
pd.show_versions()
INSTALLED VERSIONS
commit : 67a3d42
python : 3.7.5.final.0
python-bits : 64
OS : Linux
OS-release : 5.4.0-1029-aws
Version : #30~18.04.1-Ubuntu SMP Tue Oct 20 11:09:25 UTC 2020
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : C.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.1.4
numpy : 1.19.4
pytz : 2019.3
dateutil : 2.8.1
pip : 20.0.2
setuptools : 45.2.0
Cython : 0.29.15
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : 2.8.4 (dt dec pq3 ext lo64)
jinja2 : 2.11.2
IPython : 7.12.0
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.1.3
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 1.0.1
pytables : None
pyxlsb : None
s3fs : None
scipy : 1.4.1
sqlalchemy : 1.3.20
tables : None
tabulate : 0.8.7
xarray : None
xlrd : None
xlwt : None
numba : 0.52.0
The text was updated successfully, but these errors were encountered: