0

i want to add a data from dict to dataframe and display on table is possible ??

import pandas as pd
names = ['alan','jack','martin','loki','edward','sakes']
old = [18,17,20,21,22,19]

data = {'names':names,'old':old}
print(data)

after excute :

{'names': ['alan', 'jack', 'martin', 'loki', 'edward', 'sakes'], 'old': [18, 17, 20, 21, 22, 19]}

any solution possible ??

plz help me i need for us

1
  • 2
    Is data = pd.DataFrame({'names': names, 'old': old}) what you are looking for? Commented Aug 22, 2021 at 0:05

2 Answers 2

1

I can't really tell whether you want column-oriented or row-oriented.

timr@tims-gram:~/src$ cat x.py
import pandas as pd
names = ['alan','jack','martin','loki','edward','sakes']
old = [18,17,20,21,22,19]
print( pd.DataFrame( [old], columns=names ) )
print( pd.DataFrame( {'names': names, 'old':old } ) )

Output:

timr@tims-gram:~/src$ python x.py
   alan  jack  martin  loki  edward  sakes
0    18    17      20    21      22     19
    names  old
0    alan   18
1    jack   17
2  martin   20
3    loki   21
4  edward   22
5   sakes   19
Sign up to request clarification or add additional context in comments.

Comments

0

It is actually quite simple:

pd.DataFrame([data])

That should do the trick

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.