Thanks to visit codestin.com
Credit goes to github.com

Skip to content

BUG: crosstab fails with lists/tuples #44076

Closed
@rhshadrach

Description

@rhshadrach

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the master branch of pandas.

Reproducible Example

df = pd.DataFrame({'a': [1, 1, 2], 'b': [3, 4, 5]})
print(pd.crosstab(df["a"].to_list(), df["b"].to_list()))

Issue Description

The example raises a ValueError, whereas using to_numpy instead of to_list successfully produces the correct output. This is due to the use of maybe_make_list treating lists/tuples differently than other list-likes, and is related to #44056.

Expected Behavior

col_0  3  4  5
row_0         
1      1  1  0
2      0  0  1

Installed Versions

Replace this line with the output of pd.show_versions()

Metadata

Metadata

Assignees

No one assigned

    Labels

    AlgosNon-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diffBug

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions