程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Find the average value of each list in a column in pandas

編輯:Python

Click on the above “Python Home of sharing ”, Focus on

reply “ resources ” You can get a gift Python Learning materials

today

Japan

chicken

soup

Dew from tonight white , The moon is my hometown .

Hello everyone , I'm Pippi .

One 、 Preface

A few days ago Python The strongest King exchange group 【 Chen Ma Chen Cheng 】 Asked a question Pandas Issues dealt with , As shown in the figure below .

The raw data are as follows :

df = pd.DataFrame({
    'student_id': ['S001','S002','S003'],
    'marks': [[88,89,90],[78,81,60],[84,83,91]]})
df

The expected results are shown in the following figure :

Two 、 Implementation process

Method 1

here 【 Mr. Yu Liang 】 Give a feasible code , We met later , You can modify it accordingly , Yield twice the result with half the effort , The code is as follows :

df['dmean'] = df['marks'].map(lambda x: np.mean(x))

After running , The result is what you want .

Method 2

later 【 Mr. Yu Liang 】 Another optimized code is given as follows :

df['dmean'] = df['marks'].map(np.mean)
perhaps
df['dmean'] = df['marks'].apply(np.mean)

After running , The result is what you want .

It perfectly solves the problem of fans !

3、 ... and 、 summary

Hello everyone , I'm Pippi . This article mainly reviews the use of Pandas Dealing with data , In this paper, the specific analysis and code implementation are given , There are two ways , Help the fans solve the problem smoothly .

Finally, thank the fans 【 Chen Ma Chen Cheng 】 put questions to , thank 【 Luna 】、【 Mr. Yu Liang 】 Given the idea and code analysis , thank 【dcpeng】 And others participate in learning and communication .

friends , Practice it quickly ! If in the process of learning , Any problems encountered , Welcome to add my friend , I'll pull you in Python The learning exchange group discusses learning together .

------------------- End -------------------

Excellent articles in the past are recommended :

  • An article will take you through Pandas mapping API

  • Netease cloud music popular works name and link capture (html5lib piece )

  • Netease cloud music popular works name and link capture (pyquery piece )

  • Netease cloud music popular works name and link capture (bs4 piece )

Welcome to give the thumbs-up , Leaving a message. , forward , Reprint , Thank you for your company and support

Want to join Python Learning group, please reply in the background 【 Enter into Group

All rivers and mountains are always in love , Order one 【 Looking at 】 OK?


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved