苹果iPhone是全球最畅销的智能手机之一。在印度,智能手机品牌之间存在巨大的竞争,在那里你可以以iPhone一半的价格获得智能手机中的最新技术。不过,iPhone在印度的销量仍然很高。在这篇文章中,将带你完成使用Python进行iPhone销售分析的任务。
对于iPhone销售分析任务,Kaggle上有一个数据集,其中包含有关印度iPhone在Flipkart上销售的数据。这将是分析iPhone在印度销量的理想数据集。您可以从这里下载数据集。
https://www.kaggle.com/datasets/komalkhetlani/apple-iphone-data
导入必要的Python库和数据集:
import pandas as pd
import numpy as np
import plotly.express as px
import plotly.graph_objects as go
data = pd.read_csv("apple_products.csv")
print(data.head())
输出
Product Name \
0 APPLE iPhone 8 Plus (Gold, 64 GB)
1 APPLE iPhone 8 Plus (Space Grey, 256 GB)
2 APPLE iPhone 8 Plus (Silver, 256 GB)
3 APPLE iPhone 8 (Silver, 256 GB)
4 APPLE iPhone 8 (Gold, 256 GB)
Product URL Brand Sale Price \
0 https://www.flipkart.com/apple-iphone-8-plus-g... Apple 49900
1 https://www.flipkart.com/apple-iphone-8-plus-s... Apple 84900
2 https://www.flipkart.com/apple-iphone-8-plus-s... Apple 84900
3 https://www.flipkart.com/apple-iphone-8-silver... Apple 77000
4 https://www.flipkart.com/apple-iphone-8-gold-2... Apple 77000
Mrp Discount Percentage Number Of Ratings Number Of Reviews \
0 49900 0 3431 356
1 84900 0 3431 356
2 84900 0 3431 356
3 77000 0 11202 794
4 77000 0 11202 794
Upc Star Rating Ram
0 MOBEXRGV7EHHTGUH 4.6 2 GB
1 MOBEXRGVAC6TJT4F 4.6 2 GB
2 MOBEXRGVGETABXWZ 4.6 2 GB
3 MOBEXRGVMZWUHCBA 4.5 2 GB
4 MOBEXRGVPK7PFEJZ 4.5 2 GB
在继续之前,让我们快速查看一下这个数据集是否包含任何null值:
print(data.isnull().sum())
输出
Product Name 0
Product URL 0
Brand 0
Sale Price 0
Mrp 0
Discount Percentage 0
Number Of Ratings 0
Number Of Reviews 0
Upc 0
Star Rating 0
Ram 0
dtype: int64
数据集没有任何空值。现在,让我们来看看数据的描述性统计:
print(data.describe())
输出
Sale Price Mrp Discount Percentage Number Of Ratings \
count 62.000000 62.000000 62.000000 62.000000
mean 80073.887097 88058.064516 9.951613 22420.403226
std 34310.446132 34728.825597 7.608079 33768.589550
min 29999.000000 39900.000000 0.000000 542.000000
25% 49900.000000 54900.000000 6.000000 740.000000
50% 75900.000000 79900.000000 10.000000 2101.000000
75% 117100.000000 120950.000000 14.000000 43470.000000
max 140900.000000 149900.000000 29.000000 95909.000000
Number Of Reviews Star Rating
count 62.000000 62.000000
mean 1861.677419 4.575806
std 2855.883830 0.059190
min 42.000000 4.500000
25% 64.000000 4.500000
50% 180.000000 4.600000
75% 3331.000000 4.600000
max 8161.000000 4.700000
找出所有关于印度排名前10的iPhone的数据:
highest_rated = data.sort_values(by=["Star Rating"],
ascending=False)
highest_rated = highest_rated.head(10)
print(highest_rated['Product Name'])
输出
20 APPLE iPhone 11 Pro Max (Midnight Green, 64 GB)
17 APPLE iPhone 11 Pro Max (Space Grey, 64 GB)
16 APPLE iPhone 11 Pro Max (Midnight Green, 256 GB)
15 APPLE iPhone 11 Pro Max (Gold, 64 GB)
14 APPLE iPhone 11 Pro Max (Gold, 256 GB)
0 APPLE iPhone 8 Plus (Gold, 64 GB)
29 APPLE iPhone 12 (White, 128 GB)
32 APPLE iPhone 12 Pro Max (Graphite, 128 GB)
35 APPLE iPhone 12 (Black, 128 GB)
36 APPLE iPhone 12 (Blue, 128 GB)
Name: Product Name, dtype: object
根据上述数据,以下是印度最受欢迎的5款iPhone:
现在让我们来看看评分最高的iPhone的评分数量:
iphones = highest_rated["Product Name"].value_counts()
label = iphones.index
counts = highest_rated["Number Of Ratings"]
figure = px.bar(highest_rated, x=label,
y = counts,
title="Number of Ratings of Highest Rated iPhones")
figure.show()
根据上面的条形图,Apple iPhone 8 Plus(金色,64 GB)的排名最高。现在让我们来看看评分最高的iPhone的评论数量:
iphones = highest_rated["Product Name"].value_counts()
label = iphones.index
counts = highest_rated["Number Of Reviews"]
figure = px.bar(highest_rated, x=label,
y = counts,
title="Number of Reviews of Highest Rated iPhones")
figure.show()
苹果iPhone 8 Plus(金色,64 GB)也是印度最受欢迎的iPhone之一,评论数量最多。现在让我们来看看iPhone的销售价格与其评分之间的关系:
figure = px.scatter(data_frame = data, x="Number Of Ratings",
y="Sale Price", size="Discount Percentage",
trendline="ols",
title="Relationship between Sale Price and Number of Ratings of iPhones")
figure.show()
iPhone的销售价格与评分之间存在负线性关系。这意味着价格低的iPhone在印度的销量更高。现在让我们来看看iPhone的折扣百分比与评分数量之间的关系:
figure = px.scatter(data_frame = data, x="Number Of Ratings",
y="Discount Percentage", size="Sale Price",
trendline="ols",
title="Relationship between Discount Percentage and Number of Ratings of iPhones")
figure.show()
iPhone的折扣百分比与评级数量之间存在线性关系。这意味着高折扣的iPhone在印度销售得更多。
以上就是如何使用Python进行在印度的iPhone销售分析情况。这篇文章中关于iPhone在印度销售的一些要点是: