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

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

บทนำ

Vertical Bar Plot จัดกลุ่มตามตัวแปร Categorical ใช้ seaborn.barplot() ส่งตัวแปรเป็น x และ y

ขั้นตอน

  1. นำเข้าไลบรารี
  2. โหลด Cricketers2.csv
  3. วาด Vertical Bar Plot:
    sb.barplot(x=dataFrame["Role"], y=dataFrame["Matches"])

โค้ดเต็ม

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

dataFrame = pd.read_csv("C:\\Users\\amit_\\Desktop\\Cricketers2.csv")

sb.barplot(x=dataFrame["Role"], y=dataFrame["Matches"])
plt.show()

ผลลัพธ์

ได้ Vertical Bar Plot แสดงจำนวนแมตช์เฉลี่ยแยกตาม Role