MCPcopy
hub / github.com/pandas-dev/pandas / melt_stub

Function melt_stub

pandas/core/reshape/melt.py:627–644  ·  view source on GitHub ↗
(df, stub: str, i, j, value_vars, sep: str)

Source from the content-addressed store, hash-verified

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]

Callers 1

wide_to_longFunction · 0.85

Calls 5

to_numericFunction · 0.90
meltFunction · 0.85
rstripMethod · 0.80
set_indexMethod · 0.80
replaceMethod · 0.45

Tested by

no test coverage detected