1

How can I create a histogram where I can display Age in respect to TimeToPayInDays?
I can't see in the docs any y parameter for the y axis. I want to see if age influences the time it takes to pay off a loan.

#check if age influences how fast men pay what they owe to bank

print(malesSample['Age'].min())
print(malesSample['Age'].max())

# Creating histogram 
fig, ax = plt.subplots(figsize =(10, 7)) 
ax.hist(malesSample['Age'], bins = malesSample['TimeToPayInDays']) 
  
# Show plot 
plt.show()


**csv DataSet**
Age    TimeToPayInDays
22        4
24        5
39        64
17        27
36        12
51        85
42        19

Edit

As per Sergey's suggestion, I have a made a scatter plot.

print(malesSample['Age'].min()) #21.0
print(malesSample['Age'].max()) #51.0

print(feamalesSample['Age'].min()) #23.0
print(feamalesSample['Age'].max()) #44.0

age_Range = [20,25,30,35,40,45,50,55]
fig = plt.figure()
ax = fig.add_axes([0,0,1,1])

ax.scatter(x=malesSample['Paid_Off_In_Days'],y=malesSample['Age'], color='blue')

ax.set_xlabel('Paid Off In_Days')
ax.set_ylabel('Age')
ax.set_title('How does age influences time to pay off loan?')
plt.show()

enter image description here

bibscy
  • 2,598
  • 4
  • 34
  • 82
  • 3
    y in histogram is either counts or density. See https://stackoverflow.com/a/33203848/4317058. If you want to do anything different use barplot. If you want to check if there is dependence between 2 variables check out scatter plot. – Sergey Bushmanov Jul 04 '20 at 08:42
  • @SergeyBushmanov I have used scatter plot as you suggested. Is this correct? Could I interpret this graph by saying that: direction is positive, form is linear and there is strong relationship between 10 - 20 days and in 30 days? Many thanks – bibscy Jul 04 '20 at 10:18
  • Yes to a certain extent. The right way is to state contrary as an H₀ and test it with statistical tooling of your choice. – Sergey Bushmanov Jul 04 '20 at 10:25
  • How can I check the number of observations that exist in ```feamalesSample['Age']```? For example if I want to see, women between 20 - 39, 30 - 40. Not necessarily represented graphically, but printed out. – bibscy Jul 04 '20 at 16:10

0 Answers0