This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #importing relevant libraries | |
| import pandas as pd | |
| #fetching url | |
| url_1='https://genshin-impact.fandom.com/wiki/Characters/Comparison#Normal_Attacks' | |
| url_2='https://genshin-impact.fandom.com/wiki/Characters' | |
| #parsing table from url1 & url2 to dataframe | |
| tables_1 = pd.read_html(url_1) | |
| tables_2 = pd.read_html(url_2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import seaborn as sns | |
| from matplotlib import pyplot as plt | |
| # defining color palette dictionary for better visual | |
| palette_element ={"Pyro": "#FA1A0D", "Hydro": "#0D8BC4", "Geo": "#FD8D04", "Anemo": "#4CD95A", "Electro" : "#B071C1", "Cryo": "#85D8DF", "Adaptive":"#E3E3E3"} | |
| palette_nation ={"Mondstadt": "#ABCE30", "Liyue": "#FA7711", "Snezhnaya": "#58B4EE"} | |
| palette_weapon ={"Sword": "#FA1A0D", "Bow": "#0D8BC4", "Catalyst": "#FD8D04", "Claymore": "#4CD95A","Polearm" : "#B071C1"} | |
| palette_sex ={"Male": "#FA1A0D", "Female": "#FD8D04", "Player's Choice": "#E3E3E3"} | |
| palette_final = dict(palette_weapon) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # exclude Scnezhnaya (childe) and Traveler from the data | |
| exclude_scn = df3["Nation"]!="Snezhnaya" | |
| exclude_traveler = df3["Name"]!="Traveler" | |
| # compare Mondstadt & Liyue Element | |
| sns.relplot( | |
| data=df3[exclude_scn&exclude_traveler], x="DEF", y="ATK", | |
| col="Nation", hue="Element", style="Element", | |
| kind="scatter", s = 100, palette = palette_final | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # compare Mondstadt & Liyue Weapon Type | |
| sns.relplot( | |
| data=df3[exclude_scn&exclude_traveler], x="DEF", y="ATK", | |
| col="Nation", hue="Weapon", style="Weapon", | |
| kind="scatter", s = 100, palette = palette_final | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # plotting All character ATK & DEF | |
| sns.scatterplot(x=df3['DEF'], y=df3['ATK'], hue = df3["Element"], style = df3["Weapon"], palette = palette_final, s = 100); | |
| for i in range(df3.shape[0]): | |
| plt.text(x=df3.DEF[i]+2.5,y=(df3.ATK[i]+5 if df3.Name[i]=="Beidou" else df3.ATK[i]-0.2),s=df3.Name[i], | |
| fontdict=dict(color='black',size=10), | |
| bbox=dict(facecolor='pink',alpha=0.1)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import json | |
| results = """ | |
| { | |
| "type": "FeatureCollection", | |
| "features": [ | |
| { | |
| "type": "Feature", | |
| "properties": {}, | |
| "geometry": { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| x = json.loads(results) | |
| print("--- STEP a: Check keys within original json result ---") | |
| print(type(x)) | |
| print(x.keys()) | |
| print("") | |
| print("--- STEP b: Check keys within 'features' key ---") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| print("--- Retrieve nested data by keys & change 'coordinates' value to polygon ---") | |
| print("") | |
| for k,v in x3.items(): | |
| if k =='coordinates': | |
| for a in v: | |
| for b,c in enumerate(a): | |
| a[b] = str(c).replace(",","") | |
| a[:] = [",".join(a[:])] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| with ref_polygon | |
| as | |
| ( | |
| Select | |
| 'Monumen Nasional' as location_name, | |
| ST_GEOGFROMTEXT | |
| ( | |
| 'POLYGON((106.82242870330809 -6.1709343255146845,106.82217121124268 -6.181131563045953,106.8327283859253 -6.180790236097018,106.82989597320557 -6.170891658836403,106.82242870330809 -6.1709343255146845))' | |
| ) as polygon | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Importing necessary libraries | |
| import numpy as np | |
| import pandas as pd | |
| # For working with geographical data | |
| try: | |
| import geopanda as gpd | |
| from geopandas import GeoDataFrame | |
| except: | |
| !pip install --upgrade geopandas |
OlderNewer