When there are various dictionaries in the list, I wonder how to extract them and how to apply them.
For example,
x = [{'company' : 'Nexon' , 'pay': 300}, {'company' : 'Kakao' , 'pay': 200}, {'company' : 'SK' , 'pay': 100}]
I want to know how to apply Nexon's value and Kakao's value separately to the repeat statement.
list dictionary python
There are many ways, but it would be convenient to convert this into a Pandas data frame and do various operations.
Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:57:54) [MSC v.1924 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> import pandas as pd
>>> x = [{'company' : 'Nexon' , 'pay': 300}, {'company' : 'Kakao' , 'pay': 200}, {'company' : 'SK' , 'pay': 100}]
>>> df = pd.DataFrame(x)
>>> df
company pay
0 Nexon 300
1 Kakao 200
2 SK 100
>>> print(df.to_markdown())
| | | company | pay |
|---:|:----------|------:|
| | 0 | Nexon | 300 |
| | 1 | Kakao | 200 |
| | 2 | SK | 100 |
>>> df.pay.sum()
600
>>> df.pay.mean()
200.0
>>> for r in df.itertuples():
print(r)
Pandas(Index=0, company='Nexon', pay=300)
Pandas(Index=1, company='Kakao', pay=200)
Pandas(Index=2, company='SK', pay=100)
>>> for r in df.itertuples():
print(r.company, r.pay)
Nexon 300
Kakao 200
SK 100
>>>
618 GDB gets version error when attempting to debug with the Presense SDK (IDE)
925 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
577 Who developed the "avformat-59.dll" that comes with FFmpeg?
626 Uncaught (inpromise) Error on Electron: An object could not be cloned
© 2024 OneMinuteCode. All rights reserved.