SIMPLE PYTHON FOR DATA ANALYTICS PROJECT FOR BEGINNERS USING SAMPLE DATA.

image by grow.google.com
  • Python 3.6+
  • Numpy
  • Pandas
  • Matplotlib
  • Seaborn
import pandas as pd
import seaborn as sns
import matplolib.pyplot as plt
FR= pd.read_csv('Quick Survey-  FORM RESPONSES.csv')
QS= pd.read_csv('Quick Survey - PIVOTTABLE.csv')
#create variable
FR1=FR['When purchasing ice-cream, do you consider the price of the ice-cream or your favorite flavor?']
#plot,style and visualization
sns.countplot(FR1,hue=FR1,data=FR,palette='icefire_r')
sns.set_style('ticks')
sns.despine()
plt.title('PURCHASING CONSIDERATION',fontsize=14,fontfamily='verdana')
plt.xlabel('CHOICES',fontsize=14,fontfamily='verdana')
plt.ylabel('COUNT',fontsize=14,fontfamily='verdana')
plt.legend(bbox_to_anchor=(1.7,2.0))
PLOT OUTPUT
#CREATING VARIABLEQS1= QS['PURCHASING FACTOR [BRAND]']
QS2= QS['NO OF PEOPLE PER PURCHASING FACTOR.1']
#SPLIT VARIABLE
QS1=QS1.head(3)
QS2=QS2.head(3)
#convert QS2 to int
QS2=QS2.astype(int)
#use the fillna function to fill the no option choices
QS1.fillna('No Option',inplace=True)
#LABELS
plt.title('PURCHASING FACTOR BASED ON BRAND',fontsize=12,fontfamily='Verdana')
plt.xlabel('CHOICES',fontsize=12,fontfamily='Verdana')
plt.ylabel('COUNT',fontsize=12,fontfamily='Verdana')
#style
sns.despine()
cols=('#FF228B22','#FF00FF7F','#FF2E8B57')
#plot
plt.bar(QS1,QS2,color=cols,linewidth=3)
plt.style.use('seaborn')
PLOT OUTPUT
#create variable
QS3=QS['CHANGE IN FAVORITE FLAVOR IN THE LAST SIX MONTH']
QS4=QS['CHANGE CHOICES']
#split variable
QS3=QS3.head(2)
QS4=QS4.head(2)
#convert QS4 to int with astype function.
QS4=QS4.astype(int)
#labels
plt.title('CHOICE PREFERENCE IN THE LAST SIX MONTH', fontsize=12,fontfamily='verdana')
plt.xlabel('CHOICES',fontsize=12,fontfamily='verdana')
plt.ylabel('COUNT',fontsize=12,fontfamily='verdana')
#style
sns.despine()
sns.set_style('ticks')
cols=('#DDA0DD','#580F41')
#plot
plt.bar(QS3,QS4,color=cols,linewidth=5)
plt.style.use('seaborn')
PLOT OUTPUT
#create variable
QS5=QS['PRICE FACTOR[ EXPENSIVE]']
QS6=QS['NO OF CHOICES']
#split
QS5=QS5.head(2)
QS6=QS6.head(2)
#convert QS6 to int with astype function
QS6=QS6.astype(int)
#create labels
plt.title('PRICE FACTOR BASED ON HOW EXPENSIVE',fontsize=12,fontfamily='verdana')
plt.xlabel('CHOICES',fontsize=12,fontfamily='verdana')
plt.ylabel('COUNT',fontsize=12,fontfamily='verdana')
#style
cols=('#FF81C0','#F97306')
sns.despine()
sns.set_style('ticks')
#plot
plt.bar(QS5,QS6,color=cols,linewidth=5)
PLOT OUTPUT
#create variable
QS7=QS['MOST PREFERRED FLAVOR']
QS8=QS['NO OF PEOPLE PER FLAVOR']
#split
QS7=QS7.head(10)
QS8=QS8.head(10)
#convert QS8 to int using the astype function
QS8=QS8.astype(int)
`#style
sns.despine()
sns.set_style('ticks')
cols=('#DC143C','#A9561E','#8C000F','#929591','#FF796C','#7FFFD4','#D1B26F','#FFFFCB','#FBDD7E','#E6DDA6')
#plot
plt.pie(QS8,labels=QS7,colors=cols,explode=(0.1,0,0,0,0,0,0,0,0,0),autopct='%0.2f%%',radius=5)
plt.legend(bbox_to_anchor=(3.0,3.0))
PLOT OUTPUT
#create variable
QS9=QS['LEAST PREFERRED FLAVOR']
QS10=QS['NO OF PEOPLE PER FLAVOR.1']
#split
QS9=QS9.head(7)
QS10=QS10.head(7)
#convert QS10 to int using astype function
QS10=QS10.astype(int)
#style
sns.despine()
sns.set_style('ticks')
cols=('#DC143C','#A9561E','#FBDD7E','#FFD700','#7FFFD4','#D1B26F','#FFFFCB')
#plot
plt.pie(QS10,labels=QS9,colors=cols,explode=(0,0.1,0,0,0,0,0),autopct='%0.1f%%',radius=1.5)
plt.legend(bbox_to_anchor=(1.9,1.5))
PLOT OUTPUT
#create labelsplt.title('AGE COUNT FOR THE SAMPLE POPULATION',fontsize=12,fontfamily='verdana')
plt.xlabel('AGE',fontsize=12,fontfamily='verdana')
plt.ylabel('COUNT',fontsize=12,fontfamily='verdana')
#style
sns.set_style('ticks')
sns.despine()
#plot
sns.distplot(FR['Age'],kde=False)
PLOT OUTPUT
#create variable
FR2=FR['Age']
FR3=FR['If you had available resources, what ice-cream flavor would be your most preferred choice?']
#create labels
plt.title("FAVORITE FLAVOR BASED ON AGE",fontsize=12,fontfamily='verdana')
#style
sns.set_style('ticks')
sns.despine()
#plot
sns.countplot(x=FR2,hue=FR3,data=FR,palette='Spectral')
plt.legend(bbox_to_anchor=(1.5,1.1))
PLOT OUTPUT
#create variable
FR2=FR['Age']
FR4=FR['Even if you had all the resources, what ice-cream flavor would you not consider?']
#create labels
plt.title("LEAST FAVORITE FLAVOR BASED ON AGE",fontsize=12,fontfamily='verdana')
#style
sns.set_style('ticks')
sns.set_context('poster')
sns.despine()
#plot
sns.countplot(x=FR2,hue=FR4,data=FR,palette='gist_earth')
plt.legend(bbox_to_anchor=(1.9,1.4))
PLOT OUTPUT
#create variable
FR3=FR['If you had available resources, what ice-cream flavor would be your most preferred choice?']
FR5=FR['Sex']
#create label
plt.title('FAVORITE FLAVOR BASED ON SEX',fontsize=12,fontfamily='verdana')
#style
sns.set_style('ticks')
sns.despine()
#plot
sns.countplot(x=FR5,hue=FR3,data=FR,palette='Pastel2_r')
plt.legend(bbox_to_anchor=(1.5,1.1))
PLOT OUTPUT
#create variable
FR4=FR['Even if you had all the resources, what ice-cream flavor would you not consider?']
FR5=FR['Sex']
#create labels
plt.title("LEAST FAVORITE FLAVOR BASED ON SEX",fontsize=12,fontfamily='verdana')
#style
sns.set_style('ticks')
sns.despine()
#plot
ax=sns.countplot(x=FR4,hue=FR5,data=FR,palette='Paired')
ax.set(xlabel="LEAST FAVORITE FLAVOR", ylabel = "COUNT")
plt.legend(bbox_to_anchor=(1.2,1.0))
PLOT OUTPUT
#create variable
FR5=FR['Sex']
#create labels
plt.title("FREQUENCY COUNT OF THE SEX DATA",fontsize=12,fontfamily='verdana')
#style
sns.set_style('ticks')
sns.despine()
#plot
ax=sns.countplot(x=FR5,hue=FR5,data=FR)
ax.set(xlabel="SEX", ylabel = "COUNT")
plt.legend(bbox_to_anchor=(1.5,1.3))
PLOT OUTPUT

--

--

--

Hi Since you are here, I am ifeoma and I love to write, I also love to analyze data. You love to read? check my page for what I have written. Thanks for coming.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Gaussian Markov Networks & Linear Regression on Continuous Variables

Reading different data types in Pandas using complex datasets

Diving into the e-com business through data.

Data Preprocessing Using Orange Tool

Productionalizing data science through MLOps

Interview with Dask’s creator: Scale your Python from one computer to a thousand

Dealing With Poor Predictive Models

My Data Science Internship Experience

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Deborah Babundo

Deborah Babundo

Hi Since you are here, I am ifeoma and I love to write, I also love to analyze data. You love to read? check my page for what I have written. Thanks for coming.

More from Medium

CSV to JSON converter in 10 lines of code

Data types in Python

Easier Python Package Deploying