1

Current Data Frame output as below I need another Data Frame

1

import pandas as pd

df = pd.DataFrame('c:\data\text.csv')

print (df)

My output is as below:

   a b    c                                                    d         e

0  1  10 {'a1':40,'b1':60,'c1':90,'d1':100,'e1':50,'f1':75}  10000     899
1  1  65 {'a1':35,'b1':535,c1': 343,'d1':89,'e1':67,'f1':45} 90000     789

Assume my index around 50,000 to 1,00,000

I tried:

df1=pd.DataFrame(list(df.c))

print(df1)

     a1   b1    c1   d1   e1    f1                          
     40   60    90   100  50   75             
     35   535   343  89   67   45     

Then I tried

df2 = pd.DataFrame(df.a)

df3 = pd.DataFrame(df.b)

df4 = pd.DataFrame(df.d)

df5 = pd.DataFrame(df.e)


frames = [df1,df2,df3,df4,df5]

result = pd.concat(frames)

Still I am not able to get the expected result as below:

   a  b    a1  b1    c1   d1   e1    f1            d        e                
0  1  10   40  60   90   100  50   75             10000     899
1  1  65   35  535  343  89   67   45             90000      789
Sociopath
  • 13,068
  • 19
  • 47
  • 75
thangaraj1980
  • 141
  • 2
  • 11
  • 1
    Please format your code correctly. It's impossible to tell what you're looking for. – Andrew L Dec 01 '17 at 13:04
  • Hi attached the picture Just click 1(Near to Data Frame) – thangaraj1980 Dec 01 '17 at 13:07
  • 1
    Not good enough man. Need to format your code with the proper tags. – Alex F Dec 01 '17 at 13:19
  • Please refer to [this link](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) on how to post a good pandas question with reproducible results. You're more likely to get help on SO if people are able to easily understand and replicate your problem. – pault Dec 01 '17 at 13:49

1 Answers1

0

This is what you can do :-

Assuming the name of DataFrame is df, Convert each dicts of df[c] to list. Now you ned to unzip this list to add to the DataFrame. Unzip to get appropriate list and to add to df.

list_abcdef = list(map(list,zip(*[[dic['a1'],dic['b1'],dic['c1'],dic['d1'],dic['e1'],dic['f1']] for dic in df['c']])))
df1 = df[['a','b']]
df1['a1'],df1['b1'],df1['c1'],df1['d1'],df1['e1'],df1['f1'] = list_abcdef
df1['d'],df1['e'] = df['d'],df['e']

df1 should be the DataFrame you need. PLease let know if it works for you.

Abhijeetk431
  • 847
  • 1
  • 8
  • 18