import pandas as pd

"""
Explanation: Pandas Ecommerce Practice
In this project, we practice some pandas techniques using ecommerce fake transactions. The goal of this work is not to disclose 
any private information, but exercise pandas data manipulation and some basic operations.
Importing pandas package that we´ll be working with
End of explanation
"""


ecom = pd.read_csv('Ecommerce Purchases')

"""
Explanation: Reading ecommerce purchases CSV files, and loading it into the 'ecom' dataframe
End of explanation
"""


ecom.head()

"""
Explanation: Checking the head of the DataFrame
End of explanation
"""


ecom.info()

"""
Explanation: Getting some basic info about the data using the info() function
End of explanation
"""


ecom['Purchase Price'].mean()

"""
Explanation: Finding the average price
End of explanation
"""


ecom['Purchase Price'].max()

ecom['Purchase Price'].min()

"""
Explanation: What is the highest and lowest purchase value?
End of explanation
"""


ecom[ecom['Language'] == 'en'].count()

"""
Explanation: Number of people who chose English as their preferable website language
End of explanation
"""


ecom[ecom['Job'] == 'Lawyer'].count()

"""
Explanation: Number of people who have their job title of 'Lawyer"
End of explanation
"""


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

"""
Explanation: Number of people who made the purchase during AM and number of people who made a purchase during PM
End of explanation
"""


ecom['Job'].value_counts().head(5)

"""
Explanation: The 5 most common Job Titles
End of explanation
"""


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

"""
Explanation: Getting data from specific column. Purchase price from Lot = '90 WT'
End of explanation
"""


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

"""
Explanation: Email of the person with the following Credit Card Number: 4926535242672853
End of explanation
"""


ecom[(ecom['CC Provider'] == 'American Express') & (ecom['Purchase Price'] > 95)].count()

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


ecom[ecom['CC Exp Date'].str.contains('25')].count()[0]

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


def format_email(email):
    return email.split('@')[1]

#format_email('user@gmail.com')

ecom['hosts'] = ecom['Email']
ecom['hosts'] = ecom['hosts'].apply(lambda s: format_email(s))
ecom['hosts'].value_counts().head(5)

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


