(df, stub: str, i, j, value_vars, sep: str)
| 625 | return df.columns[df.columns.str.match(regex)] |
| 626 | |
| 627 | def melt_stub(df, stub: str, i, j, value_vars, sep: str): |
| 628 | newdf = melt( |
| 629 | df, |
| 630 | id_vars=i, |
| 631 | value_vars=value_vars, |
| 632 | value_name=stub.rstrip(sep), |
| 633 | var_name=j, |
| 634 | ) |
| 635 | newdf[j] = newdf[j].str.replace(re.escape(stub + sep), "", regex=True) |
| 636 | |
| 637 | # GH17627 Cast numerics suffixes to int/float |
| 638 | try: |
| 639 | newdf[j] = to_numeric(newdf[j]) |
| 640 | except (TypeError, ValueError, OverflowError): |
| 641 | # TODO: anything else to catch? |
| 642 | pass |
| 643 | |
| 644 | return newdf.set_index([*i, j]) |
| 645 | |
| 646 | if not is_list_like(stubnames): |
| 647 | stubnames = [stubnames] |
no test coverage detected