2

I god a dataFrame called df_tags, and I'd like to shift the whole dataframe by using all values of Tag column as column header name with their corresponding values as the first row of values.

I have tried using df_tags.pop suggested here because my dataframe initially was converted from a Series that was initally a dictionary, but it hasn't really been working.

df_tags.head()

           Tag     0
      0    NNP  3966
      1     IN   643
      2     CD   589
      3     DT   434
      4      (   324
      5     NN  4104
      6      :  3271
      7      )   326
      8    VBD   196
      9    VBN    92
      10    RB    77
      11  PRP$    38
      12    JJ  2034
      13     .    96
      14   VBZ   541
      15    CC   285

      ...   ...  ...  # and many many more...

into:

      NNP    IN    CD    DT    (    NN   ...
0     3966   643   589   434   324  4104 ...



deLaJU
  • 45
  • 1
  • 8

1 Answers1

4

try:

df.set_index("Tag").T

Tag   NNP   IN   CD   DT    (    NN     :  ...  VBN  RB  PRP$    JJ   .  VBZ   CC
0    3966  643  589  434  324  4104  3271  ...   92  77    38  2034  96  541  285
sushanth
  • 8,275
  • 3
  • 17
  • 28
  • 1
    It changes the indexes. So, it would be good to add df.set_index("Tag").T.reset_index(drop=True).rename_axis(None, axis=1) – aykcandem Oct 14 '21 at 12:57