(2)原神角色数据分析-2
功能一:
得到某个属性的全部角色,将其封装在class中
"""各元素角色信息:一对多"""
from pandas import DataFrame, Series
import pandas as pd
import numpy as np
class FindType:
# 自动执行,将传入参数赋值给私有属性self.Attribute
def __init__(self, attribute):
self.Attribute = attribute
def find_type(self):
role_things = pd.read_excel("C:/Users/YHT/Desktop/项目/原神各属性角色信息.xlsx", header=0, index_col=0)
# 补全
role_things = role_things.fillna(axis=0, method="ffill")
# 按照"属性"这一列的信息,将所有数据重新分组,得到一个字典
things_list = role_things.groupby("属性").groups
return role_things.loc[things_list[self.Attribute]]
功能二:
定向查找某个角色信息,传入参数为该角色的名称
"""查找对应角色:一对一"""
from pandas import DataFrame, Series
import pandas as pd
import numpy as np
class FindRole:
def __init__(self, role_name):
self.role_name = role_name
def findrole(self):
role_things = pd.read_excel("C:/Users/YHT/Desktop/项目/原神各属性角色信息.xlsx", header=0, index_col=0)
# 将属性所包含的nan,进行填充
role_things = role_things.fillna(axis=0, method="ffill")
print(role_things)
print()
all_name = role_things["角色"]
print(all_name)
num = 0
for x in all_name:
if x == self.role_name:
return_role = role_things.loc[:, "角色":]
print(return_role.iloc[num])
Attribute = return_role.iloc[num]["属性"]
Name = return_role.iloc[num]["角色"]
Hp = return_role.iloc[num]["生命值"]
Def = return_role.iloc[num]["防御力"]
Atk = return_role.iloc[num]["攻击力"]
Break = return_role.iloc[num]["突破加成"]
print(Name, Attribute, Hp, Def, Atk, Break)
num += 1
功能三:
设置对应参数,筛选角色
比如,要找出生命值高于10000,防御力高于270,攻击力高于300的角色
"""设置限制参数,查找对应角色:多对多"""
from pandas import DataFrame, Series
import pandas as pd
import numpy as np
class Num:
def __init__(self, Hp, Def, Atk):
self.Hp = Hp
self.Def = Def
self.Atk = Atk
def num(self):
role_things = pd.read_excel("C:/Users/YHT/Desktop/项目/原神各属性角色信息.xlsx", header=0, index_col=0)
role_things = role_things.fillna(axis=0, method="ffill")
if self.Hp is None:
if self.Def is None:
if self.Atk is None:
print(role_things)
else:
return_things = role_things.loc[role_things["攻击力"] > self.Atk]
print(return_things)
else:
if self.Atk is None:
return_things = role_things.loc[role_things["防御力"] > self.Def]
print(return_things)
else:
return_things = role_things.loc[
(role_things["防御力"] > self.Def) & (role_things["攻击力"] > self.Atk)]
print(return_things)
else:
if self.Def is None:
if self.Atk is None:
return_things = role_things.loc[role_things["生命值"] > self.Hp]
print(return_things)
else:
return_things = role_things.loc[
(role_things["生命值"] > self.Hp) & (role_things["攻击力"] > self.Atk)]
print(return_things)
else:
if self.Atk is None:
return_things = role_things.loc[
(role_things["生命值"] > self.Hp) & (role_things["防御力"] > self.Def)]
print(return_things)
else:
return_things = role_things.loc[
(role_things["生命值"] > self.Hp) & (role_things["防御力"] > self.Def) & (
role_things["攻击力"] > self.Atk)]
print(return_things)
功能四:
按照某一参数,将角色顺序重新排列
例如,按照生命值大小,将所有角色重新排列
"""按照某一参数重新排序:一对多"""
from pandas import DataFrame, Series
import pandas as pd
import numpy as np
class Sort:
def __init__(self, input_x):
self.input_x = input_x
def sort(self):
type_bool = True
role_things = pd.read_excel("C:/Users/YHT/Desktop/项目/原神各属性角色信息.xlsx", header=0, index_col=0)
role_things = role_things.fillna(axis=0, method="ffill")
return_things = role_things.sort_values(by=self.input_x, ascending=type_bool, axis=0)
print(return_things)