Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- import numpy as np
- pokemonTable = pd.read_csv("dataClean/Pokemon.csv")
- # Get a list of all unique values in the classification-column and sort it alphabetically
- classificationList = pokemonTable.classification.unique()
- classificationList = np.sort(classificationList)
- # Build a dictionary from the list, mapping the name to the corresponding index
- classificationDict = {name: index for index, name in enumerate(classificationList)}
- # Translate all names into numerical values using the created dictionary
- pokemonTable.classification = pokemonTable.classification.map(lambda x: classificationDict[x])
- # Create new table with all index <-> name mappings
- classificationTable = pd.DataFrame(classificationDict.keys(), columns=["name"])
- # Cleanup name of row 331 because it contains a weird value ._.
- classificationTable.name.iloc[331] = "Mischief Pokémon"
- # Replace every é with e because special character encoding in mySQL is hell ._.
- classificationTable.name.replace("é", "e", regex=True, inplace=True)
- classificationTable.to_csv("dataClean/Classifications.csv", encoding="utf-8")
- pokemonTable.to_csv("dataClean/Pokemon.csv")
Advertisement
Add Comment
Please, Sign In to add comment