Question: A basic comparison graph in Python between one data point within one column to another column and I am not sure where to start. Specifically,

A basic comparison graph in Python between one data point within one column to another column and I am not sure where to start. Specifically, I would like to compare elder financial exploitation within the suspicious activity column to gender, then repeat with that same activity and compare it to the state then age (So 4 graphs all together). I am sure I can figure out how to repeat the coding, but need help getting it started.


Below is a snapshot of some of the data I am playing around with, as well as some of my code. Any help is greatly appreciated!

#Import Modules

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from matplotlib import gridspec

Data columns (total 9 columns):

 #   Column               Non-Null Count         Dtype  

0   Suspicious Activity  3328 non-null      object 

1   Gender               3328 non-null               object 

2   Age                  3328 non-null               object 

3   State                3328 non-null                object  

4   Age               3328 non-null                    float64

Suspicious ActivityGenderStateAge
Unusual/unexplained ActivityFemaleGeorgia56
Unusual/unexplained ActivityMaleGeorgia59
Fraudulent PatternsFemaleMichigan85
Unknown Source of FundsMaleNew York60
Unknown Source of FundsFemaleNew York45
ACH FraudMaleNevada64
Fraudulent PatternsMaleMichigan69
Suspicious CallMaleCalifornia66
Suspicious CallFemalePennsylvania75
ACH FraudFemaleOhio68
ACH FraudMaleWashington48
Fraudulent PatternsMaleWashington48
Elder Financial ExploitationFemaleMississippi82
ACH FraudMaleCalifornia81
Fraudulent PatternsMaleOhio66
Elder Financial ExploitationFemaleIllinois84
Unusual/unexplained ActivityMaleNew York93
Fraudulent DocumentsFemaleCalifornia44
Fraudulent DocumentsMaleCalifornia73
Fraudulent PatternsFemaleIllinois91
Suspicious CallFemaleCalifornia62

#Group the data by "Suspicious Activity" and "Gender" and count the number of occurrences

gender_group = df.groupby(["Suspicious Activity", "Gender"]).size().reset_index(name="Count")

sns.barplot(x="Elder Financial Exploitation", y="Count", hue="Gender", data=gender_group) plt.show()

Step by Step Solution

3.33 Rating (153 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To create a basic comparison graph between Elder Financial Exploitation and other columns such as Ge... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!