0

I have this following dataset from twitter in a pandas DataFrame.

  app_clicks          billed_charge_local_micro billed_engagements card_engagements  ...   retweets tweets_send  unfollows    url_clicks
0       None  [422040000, 422040000, 422040000]       [59, 65, 63]             None  ...  [0, 2, 0]        None  [0, 0, 1]  [65, 68, 67]

I want to make that three rows, but I'm not sure the best way to do that. Looked around and saw stuff like meld, merge and stack but nothing that really looks like it is for me.

Want it to be like this (don't care about index, just for visual purposes)

Index      billed_charge_local_micro
0                    422040000
1                    422040000
2                    422040000

Thanks.

Joe Fedorowicz
  • 625
  • 2
  • 6
  • 14

1 Answers1

1

you just use different functions of dataframe:

import pandas as pd

df2 = pd.DataFrame({ 'billed_charge_local_micro' : [[422040000, 422040000, 422040000]],
                 'other1': 10000,
                 'other2': 'abc'})

print(df2)

#       billed_charge_local_micro        other1   other2
# 0  [422040000, 422040000, 422040000]   10000    abc

df = df2['billed_charge_local_micro'].apply(pd.Series)

df = df.transpose()

df.columns = ["billed_charge_local_micro"]

print (df)

result final

   billed_charge_local_micro
0  422040000
1  422040000
2  422040000
Frenchy
  • 16,386
  • 3
  • 16
  • 39