narwhals-dev / narwhals

Lightweight and extensible compatibility layer between Polars, pandas, cuDF, Modin, and more!
https://narwhals-dev.github.io/narwhals/
MIT License
218 stars 31 forks source link

DOCS: add page on how to avoid `UserWarning` for pandas groupbys #338

Open MarcoGorelli opened 3 days ago

MarcoGorelli commented 3 days ago

Currently, doing something like

df.group_by('a').agg((nw.col('b')+nw.col('c')).sum().alias('d'))

raises a warning for pandas-like dataframes

The solution to avoid the warning is to instead do

df.with_columns(d=nw.col('b')+nw.col('c')).group_by('a').agg(nw.sum('d'))

I think it would be good to have a page in the docs which explains this, perhaps next to this page: https://narwhals-dev.github.io/narwhals/other/pandas_index/, i.e. in docs/other/group_by.md

ChristianLG2 commented 1 day ago

I will work on this Issue.