NVIDIA / NVIDIA/cudf

[FEA] cudf.crosstab support for margins parameter

Open
#12,563 0 comments 0 reactions 0 assignees View on GitHub
0 - Backlog feature request Python
Dominant language
C++
Stars
9.8k
Forks
1.1k
Avg merge
3d 6m
Merged PRs (30d)
278

Description

**Is your feature request related to a problem? Please describe.**
writing code with `import cudf as pd`

**Describe the solution you'd like**
matching behavior with [`pandas.crosstab`](https://pandas.pydata.org/docs/reference/api/pandas.crosstab.html)
```
In [1]: import cudf as pd

In [2]: pd.__version__
Out[2]: '22.12.00'

In [3]: df = pd.DataFrame({"A": ["foo", "foo", "foo", "foo", "foo",
...: "bar", "bar", "bar", "bar"],
...: "B": ["one", "one", "one", "two", "two",
...: "one", "one", "two", "two"],
...: "C": ["small", "large", "large", "small",
...: "small", "large", "small", "small",
...: "large"],
...: "D": [1, 2, 2, 3, 3, 4, 5, 6, 7],
...: "E": [2, 4, 5, 5, 6, 6, 8, 9, 9]})

In [4]: pd.crosstab(df.A, df.B, margins=True)
---------------------------------------------------------------------------
NotImplementedError Traceback (most recent call last)
Cell In[4], line 1
----> 1 pd.crosstab(df.A, df.B, margins=True)

File /usr/local/lib/python3.8/dist-packages/cudf/core/reshape.py:1296, in crosstab(index, columns, values, rownames, colnames, aggfunc, margins, margins_name, dropna, normalize)
1293 df["__dummy__"] = values
1294 kwargs = {"aggfunc": aggfunc}
-> 1296 table = pivot_table(
1297 data=df,
1298 index=rownames,
1299 columns=colnames,
1300 values="__dummy__",
1301 margins=margins,
1302 margins_name=margins_name,
1303 dropna=dropna,
1304 **kwargs,
1305 )
1307 return table

File /usr/local/lib/python3.8/dist-packages/cudf/core/reshape.py:1352, in pivot_table(data, values, index, columns, aggfunc, fill_value, margins, dropna, margins_name, observed, sort)
1323 """
1324 Create a spreadsheet-style pivot table as a DataFrame.
1325
(...)
1349 An Excel style pivot table.
1350 """
1351 if margins is not False:
-> 1352 raise NotImplementedError("margins is not supported yet")
1354 if margins_name != "All":
1355 raise NotImplementedError("margins_name is not supported yet")

NotImplementedError: margins is not supported yet
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.