import numpy as np
import pandas as pd
import seaborn as sns

data = pd.read_csv('https://s3-ap-southeast-1.amazonaws.com/intro-to-ml-minhdh/EcommercePurchases.csv')

"""
Explanation: <a href="https://colab.research.google.com/github/nguyenphucdev/BookManagementSample/blob/master/NguyenPhuc_Ecommerce%2BPurchases%2BExercise%2B_.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>
Ecommerce Purchases Exercise
In this Exercise you will be given some Fake Data about some purchases done through Amazon! Just go ahead and follow the directions and try your best to answer the questions and complete the tasks. Feel free to reference the solutions. Most of the tasks can be solved in different ways. For the most part, the questions get progressively harder.
Please excuse anything that doesn't make "Real-World" sense in the dataframe, all the data is fake and made-up.
Also note that all of these questions can be answered with one line of code.

 Import pandas and read in the Ecommerce Purchases csv file and set it to a DataFrame called ecom.
End of explanation
"""


data.head()

"""
Explanation: Check the head of the DataFrame.
End of explanation
"""


data.shape

"""
Explanation: How many rows and columns are there?
End of explanation
"""


data["Purchase Price"].mean()

"""
Explanation: What is the average Purchase Price?
End of explanation
"""


data["Purchase Price"].max()

data["Purchase Price"].min()

"""
Explanation: What were the highest and lowest purchase prices?
End of explanation
"""


data[data['Language'] == 'en'].count()[0]

"""
Explanation: How many people have English 'en' as their Language of choice on the website?
End of explanation
"""


data[data['Job'] == 'Lawyer'].count()[0]

"""
Explanation: How many people have the job title of "Lawyer" ?
End of explanation
"""


data['AM or PM'].value_counts()

"""
Explanation: How many people made the purchase during the AM and how many people made the purchase during PM ? 
(Hint: Check out value_counts() )
End of explanation
"""


data['Job'].value_counts().head()

"""
Explanation: What are the 5 most common Job Titles?
End of explanation
"""


data['Purchase Price'][data['Lot'] == '90 WT']

"""
Explanation: Someone made a purchase that came from Lot: "90 WT" , what was the Purchase Price for this transaction?
End of explanation
"""


data['Email'][data['Credit Card'] == 4926535242672853]

"""
Explanation: What is the email of the person with the following Credit Card Number: 4926535242672853
End of explanation
"""


data2 = data[data['Purchase Price'] > 95]
data2[data2['CC Provider'] == 'American Express'].count()[0]

"""
Explanation: How many people have American Express as their Credit Card Provider and made a purchase above $95 ?
End of explanation
"""


data[data['CC Exp Date'].str.contains('/25')].shape[0]

"""
Explanation: Hard: How many people have a credit card that expires in 2025?
End of explanation
"""



data[data['Email'].split('@')]

"""
Explanation: Hard: What are the top 5 most popular email providers/hosts (e.g. gmail.com, yahoo.com, etc...)
End of explanation
"""


sns.distplot(data['Purchase Price'])

"""
Explanation: Data Visualization
 Implement a bar plot for top 5 most popular email providers/hosts 
 Plot distribution of Purchase Price
End of explanation
"""


sns.countplot(data['Language'])

Feel free to plot more graphs to dive deeper into the dataset.

"""
Explanation: Implement countplot on Language
End of explanation
"""


