Python Forum
Control chart in Python
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Control chart in Python
#1
Hello,

I need to develop control chart (P chart) in Python with the purpose of highlighting the violating points to end users.

Please suggest.

Regards,
K.Sasidharan
Reply
#2
That should be pretty easy to do with matplotlib.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
Hi,

Its great to hear, can you please let me know how to use this module to create P chart for sample data as below.
Sample Data:
ID --> Supplier-->Month-->Sample_Size-->Defective
21 --> Supplier1 -->201906 -->10440 --> 4
33 --> Supplier1 -->201907 -->14490 --> 6
44 --> Supplier2 -->201906 -->4199 --> 2
21 --> Supplier3 -->201906 -->7356 --> 1
21 --> Supplier1 -->201908 -->1487 --> 10
71 --> Supplier2 -->201910 -->980 --> 3
81 --> Supplier1 -->201910 -->12056 --> 5
35 --> Supplier1 -->202004 -->1177 --> 12
18 --> Supplier2 -->202001 -->16234 --> 1
123 -->Supplier3 -->201908 -->3800 --> 4
213 -->Supplier1 -->201912 -->15 --> 0
22 --> Supplier2 -->202001 -->6 --> 0
Reply
#4
We don't generally write code for people here, we help them fix code that they are working on.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#5
Hi,

Thank you.. sure I understand and here is my code where I used "pyspc" module but it doesnt allow me to specify parameters.
import pandas as pd
from pyspc import *

data = pd.DataFrame(your_sample_data_here)

# selecting first row as header
data.columns = data.iloc[0]
data = data.reindex(data.index.drop(0))

# selecting last two columns
data = data[data.columns[-2:]]

# Creating chart
p = spc(data) + p() + rules()
Then as suggested I used "Matplotlib" shown below
import os
import sys
import matplotlib
import matplotlib.pyplot as plt
%matplotlib inline
font = {'size': 15}
matplotlib.rc('font', **font)
curdir = !pwd
rootdir = os.path.abspath(curdir[0])
sys.path.append(rootdir)
plt.plot('Data')
plt.axis([Data.Monthkey])
plt.show()
but not sure about P chart option.
Reply
#6
Any idea.. I am really struggling with this, need to complete ASAP
Reply
#7
Well, it kind of hard to help, you have posted any code that is vaguely runnable, and I'm not familiar with control charts. You would need to plot the data points to get the main line using matplotlib.pyplot.plot. That's pretty simple, you just pass the lists of x and y coordinates as parameters. Then you need to calculate the mean and standard deviation of your data. Numpy can calculate that if you load your data into a numpy array. Then you need to plot lines for the mean and 3*sigma (or whatever you choose), which can be done with matplotlib.pyplot.hlines (see this Stack Overflow question).
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020