Home > Software design >  What is the stubname for fields with multiple separators?
What is the stubname for fields with multiple separators?

Time:05-07

I'm trying to use pd.wide_to_long and I'm a little bit stumped on using the stubnames parameter:

enter image description here

Expected behavior: the transformation of a wide format df to a long format.

Current behavior: returns an empty row df with no other changes. I believe it's because of an improper use of stubnames or the sep parameter.

Attempts:

  • stubnames = "0.outbreakMap."

  • stubnames = "0.outbreakMap"

  • stubnames = "outbreakMap"

  • stubnames = "outbreakMap."

Thank you.

CodePudding user response:

Try to swap i and j then specify the suffix (wildcard):

>>> pd.wide_to_long(df, stubnames='0.outbreakMap', i='reportInfoId', j='id', 
                    sep='.', suffix='.*').reset_index()

   reportInfoId                            id 0.outbreakMap
0          2428       1000011041.oieReference    1000011041
1          2428  1000011041.outbreakStartDate    2010-02-03


>>> df
   reportInfoId  0.outbreakMap.1000011041.oieReference 0.outbreakMap.1000011041.outbreakStartDate
0          2428                             1000011041                                 2010-02-03
  • Related