Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

Python Pandas - วาด Vertical Point Plots จัดกลุ่มตามตัวแปร Categorical ด้วย Seaborn

บทนำ

Vertical Point Plot จัดกลุ่มตามตัวแปร Categorical ใช้ seaborn.pointplot() ส่งตัวแปรเป็น x หรือ y

ขั้นตอน

  1. นำเข้าไลบรารี
  2. โหลด Cricketers.csv
  3. วาด Vertical Point Plot:
    sb.pointplot(dataFrame['Role'], dataFrame['Age'])

โค้ดเต็ม

import seaborn as sb
import pandas as pd
import matplotlib.pyplot as plt

dataFrame = pd.read_csv("C:\\Users\\amit_\\Desktop\\Cricketers.csv")
sb.set_theme(style="darkgrid")

sb.pointplot(dataFrame['Role'], dataFrame['Age'])
plt.show()

ผลลัพธ์

ได้ Vertical Point Plot แสดงอายุเฉลี่ยแยกตาม Role (Batsman/Bowler)