-
大小: 1.04MB文件類型: .zip金幣: 2下載: 1 次發(fā)布日期: 2024-01-23
- 語言: Python
- 標(biāo)簽: 數(shù)據(jù)分析??
資源簡介
星巴克數(shù)據(jù)分析案例及數(shù)據(jù)集,python語言,內(nèi)含相應(yīng)數(shù)據(jù)集,代碼可運(yùn)行。

代碼片段和文件信息
import?numpy?as?np
import?pandas?as?pd
data?=?pd.read_csv(‘directory.csv‘)#?讀取數(shù)據(jù),將文件轉(zhuǎn)換為Dataframe格式
data.head()
data.describe()#?用于查看數(shù)值型數(shù)據(jù)的分布情況
data.info()#?用于查看各字段的數(shù)據(jù)類型,以及缺失情況
data[‘Brand‘].unique()#?查看唯一品牌的類型
data?=?data[data[‘Brand‘]?==?‘Starbucks‘]#?只獲取品牌為Starbucks
data[‘Brand‘].unique()
data.isnull().sum()#?各個字段缺失值的數(shù)量
data[data[‘City‘].isnull()]#?查看缺失城市是哪些
#?用國家字段填充到城市字段上
def?fill_na(x):
????return?x
data[‘City‘]?=?data[‘City‘].fillna(fill_na(data[‘State/Province‘]))
data[data[‘Country‘]?==?‘EG‘]
#臺灣被美國當(dāng)成一個國家,把他重新賦值到中國來
data[‘Country‘][data[‘Country‘]?==?‘TW‘]?=?‘CN‘
country_count?=?data[‘Country‘].value_counts()[0:10]
import?matplotlib.pyplot?as?plt
#import?matplotlib
#matplotlib.matplotlib_fname()??#?將會獲得matplotlib包所在文件夾
plt.rcParams[‘font.sans-serif‘]?=?[‘simhei‘]#?指定默認(rèn)字體
plt.rcParams[‘a(chǎn)xes.unicode_minus‘]?=?False#?用來正常顯示坐標(biāo)軸上的負(fù)號(‘-’)
plt.title(‘全球星巴克數(shù)量前十的國家‘)
country_count.plot(kind?=?‘bar‘)
country_city_count?=?data[‘City‘].value_counts()[0:10]
plt.title(‘全球星巴克數(shù)量前十的城市‘)
country_city_count.plot(kind?=?‘barh‘)
china_data?=?data[data[‘Country‘]?==?‘CN‘]
china_data.head()
city_count?=?china_data[‘City‘].value_counts()[0:10]
plt.title(‘中國星巴克數(shù)量前十的城市‘)
city_count.plot(kind?=?‘barh‘)
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????4111462??2017-02-14?07:05??星巴克數(shù)據(jù)分析案例及數(shù)據(jù)集\directory.csv
?????文件????????1447??2019-11-07?13:52??星巴克數(shù)據(jù)分析案例及數(shù)據(jù)集\星巴克數(shù)據(jù)分析.py
?????目錄???????????0??2019-11-07?13:52??星巴克數(shù)據(jù)分析案例及數(shù)據(jù)集\
評論
共有 條評論