pandas.wide_to_long
pandas 3.1.1 · General functions · function
Turn column families such as sales_2025 and sales_2026 into rows using shared prefixes and changing suffixes.
Call syntax
pd.wide_to_long(df, stubnames, i, j, sep='', suffix='\\d+')Run the example
Edit the example and select Run Python to see the result.
Parameters
| Parameter | Requirement | Accepted values and behavior |
|---|---|---|
df |
Required Positional or keyword |
DataFrame |
stubnames |
Required Positional or keyword |
str or list-like |
i |
Required Positional or keyword |
str or list-like |
j |
Required Positional or keyword |
str |
sep |
Optional Positional or keyword Default '' |
str Specify the separator between fields or string pieces. |
suffix |
Optional Positional or keyword Default '\\d+' |
str Set the text added to labels or the pattern used for wide-column suffixes. |
Returns
DataFrame