星际争霸游戏战队案例分析
生活随笔
收集整理的這篇文章主要介紹了
星际争霸游戏战队案例分析
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
#1.加載并查看數據基本信息
def read_dataset(file_root):dataframe=pd.read_csv(file_root)print("數據的基本信息:")print(dataframe.info())print("數據集有%i行,%i列"%(dataframe.shape[0],dataframe.shape[1]))print("數據預覽:")print(dataframe.head())return dataframe
#2.處理缺失數據
def processing_missing_data(dataframe):if (dataframe.isnull().values.any()):dataframe.fillna(0.)#dataframe.dropna()return dataframe
#3.可視化數據
def visualize_data(dataframe,save_fig=True):fig=plt.figure()ax1=fig.add_subplot(2,2,1)ax2=fig.add_subplot(2,2,2)ax3=fig.add_subplot(2,2,3)ax4=fig.add_subplot(2,2,4)#解決matplotlib顯示中文的問題plt.rcParams["font.sans-serif"]=["SimHei"]#指定默認字體plt.rcParams["axes.unicode_minus"]=False#解決保存圖像是負號顯示為方塊問題fig.suptitle("戰隊屬性")ax1.scatter(dataframe["LeagueIndex"],dataframe["Age"])ax1.set_xlabel("戰隊")ax1.set_ylabel("年齡")ax2.scatter(dataframe["LeagueIndex"],dataframe["HoursPerWeek"])ax2.set_xlabel("戰隊")ax2.set_ylabel("每周游戲時間")ax3.scatter(dataframe["LeagueIndex"], dataframe["APM"])ax3.set_xlabel("戰隊")ax3.set_ylabel("APM")ax4.scatter(dataframe["LeagueIndex"], dataframe["WorkersMade"])ax4.set_xlabel("戰隊")ax4.set_ylabel("單位時間建造數")if save_fig:plt.savefig("H:/pythonfigure/league.png")plt.show()
#4.可視化數據統計
def visualize_league_data(dataframe,attribution,save_fig=True):min_data=[]max_data=[]mean_data=[]for i in range(1,9):filter_data=dataframe.ix[dataframe["LeagueIndex"]==i,attribution]min_data.append(filter_data.min())max_data.append(filter_data.max())mean_data.append(filter_data.mean())league_series=pd.Series(range(1,9),name="LeagueIndex")min_series=pd.Series(min_data,name="min")max_series=pd.Series(max_data,name="max")mean_series=pd.Series(mean_data,name="mean")dataframe_rst=pd.concat([league_series,min_series,max_series,mean_series],axis=1)if save_fig:dataframe_rst.to_csv("H:/pythonfigure/min_max_mean.csv")#統計值可視化fig=plt.figure()ax1=fig.add_subplot(1,1,1)#解決matplotlib顯示中文問題plt.rcParams["font.sans-serif"]=["SimHei"]#指定默認字體plt.rcParams['axes.unicode_minus'] = False # 解決保存圖像是負號'-'顯示為方塊的問題ax1.plot(dataframe_rst["LeagueIndex"],dataframe_rst["min"],color='b')ax1.plot(dataframe_rst["LeagueIndex"],dataframe_rst["max"],color='g')ax1.plot(dataframe_rst["LeagueIndex"],dataframe_rst["mean"],color="r")ax1.set_xlabel("戰隊")ax1.set_ylabel("attribution")ax1.legend()if save_fig:plt.savefig("H:/pythonfigure/min_max_mean.png")plt.show()#加載數據
dataframe=read_dataset("H:/pythonfigure/starcraft.csv")
#處理缺失數據
df_data=processing_missing_data(dataframe)
#可視化數據
visualize_data(df_data,save_fig=True)
#可視化統計指標
visualize_league_data(df_data,"Age",save_fig=True)
visualize_league_data(df_data,"HoursPerWeek",save_fig=True)
visualize_league_data(df_data,"APM",save_fig=True)
visualize_league_data(df_data,"WorkersMade",save_fig=True)
總結
以上是生活随笔為你收集整理的星际争霸游戏战队案例分析的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 组队学习可汗学院统计学1
- 下一篇: java直线绕点旋转_几何画板中怎样使直