<jupyter_start><jupyter_text>loc and iloc<jupyter_code>gpaoverall = nls97.gpaoverall
# gpaoverall.mean()
gpaoverall.describe()
gpaoverall.quantile(np.arange(0.1,1.1,0.1))
(gpaoverall>4).any()<jupyter_output><empty_output><jupyter_text>Categorical<jupyter_code>landtemps = pd.read_csv("data/landtemps2019avgs.csv")
landtemps.elevation.quantile(np.arange(0.2,1.1,0.2))
# where method to create a categorical series
landtemps["elevation_group"] = np.where(landtemps.elevation>landtemps.elevation.quantile(0.8), "High","Low")
landtemps.elevation_group = landtemps.elevation_group.astype("category")
landtemps.groupby(["elevation_group"])["elevation"].agg(["count","min","max"])
# where method to create a categorical series more than 2
landtemps["elevation_group"] = np.where(
    landtemps.elevation>landtemps.elevation.quantile(0.8), "High", 
    np.where(landtemps.elevation>landtemps.elevation.median(), "Medium","Low")
    )
landtemps.groupby(["elevation_group"])["elevation"].agg(["count", "min", "max"])
test = [
    (nls97.gpaoverall<2)&(nls97.highestdegree=="0. None"), 
    nls97.highestdegree == "0. None", 
    nls97.gpaoverall<2
    ]
result = [
    "1. Low GPA and No Diploma", 
    "2. No Diploma", 
    "3. Low GPA"
    ]
nls97["hsachieve"] = np.select(test, result, "4. Did Okay")

nls97[["hsachieve", "gpaoverall", "highestdegree"]].head()
#use apply, more on this later, located on 277 of 439<jupyter_output><empty_output><jupyter_text>String cleaning<jupyter_code>nls97.maritalstatus.value_counts()
test = [
    nls97.maritalstatus == "Married", 
    nls97.maritalstatus == "Never-married", 
    nls97.maritalstatus == "Divorced",
    nls97.maritalstatus == "Separated",
    nls97.maritalstatus == "Widowed"
    ]
result = [
    "Yes", 
    "No", 
    "Yes",
    "Yes",
    "Yes"
    ]

nls97["evermarried"] = np.select(test, result, "Unknown")

nls97[["maritalstatus", "evermarried"]].head()
pd.crosstab(nls97.maritalstatus, nls97.evermarried)
nls97.evermarried.value_counts()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17004448838358874, 'fraction_numerical': 0.03559070687098369, 'mean_word_length': 5.571428571428571, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '76281', 'license': 'MIT', 'n_tokens_mistral': 860, 'n_tokens_neox': 787, 'n_words': 109, 'path': 'Chapter04/myCode/DC2-eda-pd.ipynb', 'repo_name': 'royceto/Python-Data-Cleaning-Cookbook', 'size': '2023'}