# Define as informações a serem pesquisadas em cada linha
required_info = [
"Race",
"Age",
"Gender",
"Type",
"Affiliation",
"Occupation",
"Hair color",
"Eye color",
"Job class",
"Weapon",
"Armor",
]
# Cria um dicionário para as informações a serem extraídas
info_dict = {info: [] for info in required_info}
info_dict["name"] = [] # Cria a coluna name
for row in info_df["info"]: # Para cada linha na coluna info
# Extrai a primeira strings correspondente ao nome do personagem
name = row[0]
info_dict["name"].append(name) # Acrescenta o nome a coluna name
# Para cada index e string da linha
for i, s in enumerate(row):
# Verifica a ocorrência das informações desejadas na lista required_info
if s in required_info:
if i + 1 < len(row):
# Caso a condição é satisfeita, extrai a proxima string (resposta da informação desejada) e acrescenta no dicionário
info_dict[s].append(row[i + 1])
else:
# Caso a informação não esteja disponivel, ou não exista, imputa "Unknown/Not available"
info_dict[s].append("Unknown")
# Caso alguma das informações desejadas não exista, imputa "Unknown/Not available", isso é necessário para evitar erro de index
for info in required_info:
if info not in row:
# Caso a informação não esteja disponivel, ou não exista, imputa "Unknown/Not available"
info_dict[info].append("Unknown")
# Cria um dataframe a partir do dicionário
info_dataframe = pd.DataFrame(info_dict)
col_order = ["name"] + required_info
info_dataframe = info_dataframe[col_order] # Reordena o dataframe
# define a function to extract the main number from a string
def extract_main_number(s):
# use regular expressions to extract the digits before the first non-digit character
match = re.search(r"\d+", s)
if match is not None:
return match.group()
else:
return None
info_dataframe["Age"] = info_dataframe["Age"].apply(extract_main_number)
info_dataframe["Age"] = info_dataframe["Age"].fillna(pd.NA)
info_dataframe["Age"] = pd.to_numeric(info_dataframe["Age"], errors="coerce").astype(
"Int64"
)
info_dataframe["Race"] = info_dataframe["Race"].str.replace('"', "")
# Substituindo termos ambiguos
race_mapping = {
"Mystel": "Miqo'te",
"Seekers of the Sun Miqote": "Miqo'te",
"Miqote / Unknown": "Miqo'te",
"Keeper of the Moon Miqote": "Miqo'te",
"Seeker of the Sun Miqote": "Miqo'te",
"Miqote (formerly)": "Miqo'te",
"Xaela Au Ra": "Au'ra",
"Au Ra": "Au'ra",
"Drahn": "Au'ra",
"Raen Au Ra": "Au'ra",
"Au Ra (formerly)": "Au'ra",
"Highlander Hyur": "Hyur",
"Hume": "Hyur",
"Hyur/Garlean": "Hyur",
"Midlander Hyur": "Hyur",
"Far Eastern Hyur": "Hyur",
"Human": "Hyur",
"Hyur (Lich)": "Hyur",
"Wildwood Elezen": "Elezen",
"Ishgardian Elezen": "Elezen",
"Elezen (formerly)": "Elezen",
"Elf": "Elezen",
"Duskwight Elezen": "Elezen",
"Sea Wolf Roegadyn": "Roegadyn",
"Roegadyn (formerly)": "Roegadyn",
"Galdjent": "Roegadyn",
"Roegadyn (Biggs)": "Roegadyn",
"Hellsguard Roegadyn": "Roegadyn",
"Viis": "Viera",
"Veena Viera": "Viera",
"Rava Viera": "Viera",
"Dunesfolk Lalafell": "Lalafell",
"Dwarf": "Lalafell",
"Plainsfolk Lalafell": "Lalafell",
"Plainsfolk Lalafell (formerly)": "Lalafell",
"Lalafell (formerly)": "Lalafell",
"Ronso": "Hrothgar",
"Garlean (as Rullus)": "Garlean",
"Dragon (Vrtra)": "Dragon",
"Pixie (formerly)": "Pixie",
"Porxie": "Familiar",
"Auspices": "Auspice",
"Blue Kojin": "Kojin",
"Hume/Sin eater hybrid": "Hyur/Sin eater hybrid",
}
info_dataframe["Race"] = info_dataframe["Race"].replace(race_mapping)
info_dataframe