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

วิธีใช้ Countplot visualize ข้อมูลใน Seaborn Python

Seaborn visualize ข้อมูล barplot: categorical vs continuous countplot: กรณีพิเศษของ barplot แสดงจำนวน observations ในแต่ละ category แทนที่จะคำนวณค่าสถิติของตัวแปรที่สอง

ตัวอย่าง

import pandas as pd
import seaborn as sb
from matplotlib import pyplot as plt
my_df = sb.load_dataset('titanic')
sb.countplot(x="class", data=my_df, palette="Blues")
plt.show()

ผลลัพธ์

วิธีใช้ Countplot visualize ข้อมูลใน Seaborn Python

คำอธิบาย

  • นำเข้าแพ็กเกจ
  • โหลดข้อมูล 'titanic' จาก seaborn
  • เก็บใน DataFrame
  • ใช้ 'countplot' visualize
  • ระบุ dataframe, x, palette
  • แสดงผล

Countplot = barplot ที่ height = count ของแต่ละ category ใช้สำหรับ categorical variable เดียว