@@ -894,10 +894,10 @@ def wide_to_long(df, stubnames, i, j, sep="", suffix='\d+'):
894
894
----------
895
895
df : DataFrame
896
896
The wide-format DataFrame
897
- stubnames : list or string
897
+ stubnames : str or list-like
898
898
The stub name(s). The wide format variables are assumed to
899
899
start with the stub names.
900
- i : list or string
900
+ i : str or list-like
901
901
Column(s) to use as id variable(s)
902
902
j : str
903
903
The name of the subobservation variable. What you wish to name your
@@ -993,7 +993,7 @@ def wide_to_long(df, stubnames, i, j, sep="", suffix='\d+'):
993
993
Going from long back to wide just takes some creative use of `unstack`
994
994
995
995
>>> w = l.reset_index().set_index(['famid', 'birth', 'age']).unstack()
996
- >>> w.columns = [name + suffix for name, suffix in wide. columns.tolist()]
996
+ >>> w.columns = pd.Index(w. columns).str.join('')
997
997
>>> w.reset_index()
998
998
famid birth ht1 ht2
999
999
0 1 1 2.8 3.4
@@ -1065,11 +1065,15 @@ def melt_stub(df, stub, i, j, value_vars, sep):
1065
1065
if any (map (lambda s : s in df .columns .tolist (), stubnames )):
1066
1066
raise ValueError ("stubname can't be identical to a column name" )
1067
1067
1068
- if not isinstance (stubnames , list ):
1068
+ if not is_list_like (stubnames ):
1069
1069
stubnames = [stubnames ]
1070
+ else :
1071
+ stubnames = list (stubnames )
1070
1072
1071
- if not isinstance ( i , list ):
1073
+ if not is_list_like ( i ):
1072
1074
i = [i ]
1075
+ else :
1076
+ i = list (i )
1073
1077
1074
1078
value_vars = list (map (lambda stub :
1075
1079
get_var_names (df , stub , sep , suffix ), stubnames ))
0 commit comments