Pandas : Data Processing and Visulisation with Python (Python Exercise 26)

Data Processing and Visulisation with Python

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. Most of the tasks can be solved in different ways.

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.

import pandas as pd
import numpy as np
ecom = pd.read_csv("Ecommerce Purchases")

Check the head of the DataFrame.

ecom.head(3)

在这里插入图片描述

How many rows and columns are there?

ecom.shape

在这里插入图片描述

Check the info().

ecom.info()

在这里插入图片描述

What is the average Purchase Price?

ecom['Purchase Price'].mean()

What are the highest and lowest purchase prices?

ecom['Purchase Price'].max()

ecom['Purchase Price'].min()

How many people have English ‘en’ as their Language of choice on the website?

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

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

在这里插入图片描述

How many people have the job title of “Lawyer” ?

ecom[ecom['Job']=='Lawyer'].shape[0]

count = 0
for i in ecom['Job']:
    if 'Lawyer' in i:
        count +=1
count

在这里插入图片描述

How many people made the purchase during the AM and how many people made the purchase during PM ?

Hint:

Check out value_counts()

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

在这里插入图片描述

What are the 5 most common Job Titles?

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

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

在这里插入图片描述

Someone made a purchase that came from Lot: “90 WT” , what was the Purchase Price for this transaction?

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

在这里插入图片描述

What is the email of the person with the following Credit Card Number: 4926535242672853

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

在这里插入图片描述

How many people have American Express as their Credit Card Provider and made a purchase above $95 ?

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

How many people have a credit card that expires in 2025?

sum(ecom['CC Exp Date'].apply(lambda x : x.split('/')[1]) == '25')

What are the top 5 most popular email providers/hosts (e.g. gmail.com, yahoo.com, etc…)

ecom['Email'].apply(lambda x : x.split('@')[1]).value_counts()[:5]
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值