Q-Q plot with data frames in Python

I need some help. I want to draw a Q-Q plot for each column of a dataframe in python. Here is the sample dataframe from my database:

my_dict = {'age':[16,33,54,37,66,17,5,14,22,42],
           'avg_glucose_level':[88.85,121.04,129.16,87.16,103.01,68.66,84.93,111.27,79.81,55.22]}
df_sample = pd.DataFrame(my_dict)

Upvotes: 1

Views: 3705

Answers (1)

CognitiveRobot
CognitiveRobot

Reputation: 1505

You may use matplotlib and statesmodels library (go to the links if you need to install them) as follows:

import numpy as np
import matplotlib.pyplot as plt
import statsmodels.api as sm

my_dict = {'age':[16,33,54,37,66,17,5,14,22,42],
           'avg_glucose_level':[88.85,121.04,129.16,87.16,103.01,68.66,84.93,111.27,79.81,55.22]}
df = pd.DataFrame(my_dict)

a = np.random.normal(5, 5, 250)
sm.qqplot(df['age'])
sm.qqplot(df['avg_glucose_level'])
plt.show()

Upvotes: 1

Related Questions