我有一個csv文件,其中包含Gender和Marriage狀態以及下面的更多列。如何在圖中繪製pandas groupby值?
Loan_ID,Gender,Married,Dependents,Education,Self_Employed,ApplicantIncome,CoapplicantIncome,LoanAmount,Loan_Amount_Term,Credit_History,Property_Area,Loan_Status
LP001002,Male,No,0,Graduate,No,5849,0,,360,1,Urban,Y
LP001003,Male,Yes,1,Graduate,No,4583,1508,128,360,1,Rural,N
LP001005,Male,Yes,0,Graduate,Yes,3000,0,66,360,1,Urban,Y
LP001006,Male,Yes,0,Not Graduate,No,2583,2358,120,360,1,Urban,Y
LP001008,Male,No,0,Graduate,No,6000,0,141,360,1,Urban,Y
LP001011,Male,Yes,2,Graduate,Yes,5417,4196,267,360,1,Urban,Y
我想計數沒有。已婚男性和女性,並顯示在圖中相同的如下圖所示
下面是我使用的代碼:
import csv
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
if __name__ == '__main__':
x=[]
y=[]
df = pd.read_csv(
"/home/train.csv",usecols=[1,2]).dropna(subset=['Gender','Married']) # Reading the dataset in a dataframe using Pandas
groups = df.groupby(['Gender','Married'])['Married'].apply(lambda x: x.count())
print(groups)
組後我有以下結果:
Gender Married
Female No 80
Yes 31
Male No 130
Yes 357
我想像下面
您需要更具體地瞭解您遇到的問題。 –
只是瀏覽優秀的[熊貓文檔](https://pandas.pydata.org/pandas-docs/stable/visualization.html) – Quickbeam2k1
@AndrewL我想有一個圖表沒有。的已婚男性和女性。使用DF我可以groupby和計數已婚男女。我想代表相同的使用python圖表 – pythonaddict