Skip to content

Incorrect example in wide_to_long docstring #25733

Closed
@TomAugspurger

Description

@TomAugspurger

The last example at https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.wide_to_long.html is incorrect.

>>> df = pd.DataFrame({
...     'famid': [1, 1, 1, 2, 2, 2, 3, 3, 3],
...     'birth': [1, 2, 3, 1, 2, 3, 1, 2, 3],
...     'ht_one': [2.8, 2.9, 2.2, 2, 1.8, 1.9, 2.2, 2.3, 2.1],
...     'ht_two': [3.4, 3.8, 2.9, 3.2, 2.8, 2.4, 3.3, 3.4, 2.9]
... })
>>> df
>>> l = pd.wide_to_long(df, stubnames='ht', i=['famid', 'birth'], j='age',
                        sep='_', suffix='\w')
>>> l

locally, l is an empty dataframe

Empty DataFrame
Columns: [ht_two, ht_one, ht]
Index: []

I think the suffix should be \w+.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions