Erstellen Sie eine Rangliste aus den Ergebnissen der JFL-Spiele
Entspricht dem Scraping der vorherigen Rangliste aus JFL-Match-Ergebnissen erstellen
import requests
from bs4 import BeautifulSoup
url = "http://www.jfl.or.jp/jfl-pc/view/s.php?a=1542&f=2020A001_spc.html"
r = requests.get(url)
r.raise_for_status()
soup = BeautifulSoup(r.content, "html.parser")
data = []
for table in soup.find_all("table", class_="table-data"):
trs = table.find_all("tr")
th = int(trs[0].th.get_text(strip=True).strip("Sektion"))
for i, tr in enumerate(trs[1:], 1):
tds = [td.get_text(strip=True) for td in tr.find_all("td")]
data.append([th, i] + tds)
import pandas as pd
df = pd.DataFrame(
data, columns=["Sektion", "Nummer", "Datum", "Zeit", "Zuhause", "Ergebnis", "Weg", "Stadion", "Bemerkungen"]
)
df.set_index(["Sektion", "Nummer"], inplace=True)
df
df_score = (
df["Ergebnis"].str.split("-", expand=True).rename(columns={0: "Home Score", 1: "Auswärtspunktzahl"})
)
df_score["Home Score"] = pd.to_numeric(df_score["Home Score"], errors="coerce").astype("Int64")
df_score["Auswärtspunktzahl"] = pd.to_numeric(df_score["Auswärtspunktzahl"], errors="coerce").astype("Int64")
df1 = pd.concat([df, df_score], axis=1).dropna(subset=["Home Score", "Auswärtspunktzahl"])
#Nur Home-Ergebnisse
df_home = df1.loc[:, ["Zuhause", "Weg", "Zuhause得点", "Weg得点"]].copy()
df_home.rename(
columns={"Zuhause": "Teamname", "Weg": "Gegner", "ZuhauseErgebnis": "Ergebnis", "WegErgebnis": "Zugegeben"}, inplace=True
)
df_home["Krieg"] = "H"
df_home.head()
#Nur Auswärtsergebnisse
df_away = df1.loc[:, ["Weg", "Zuhause", "Weg得点", "Zuhause得点"]].copy()
df_away.rename(
columns={"Weg": "Teamname", "Zuhause": "Gegner", "WegErgebnis": "Ergebnis", "ZuhauseErgebnis": "Zugegeben"}, inplace=True
)
df_away["Krieg"] = "A"
df_away.head()
#Kombinieren Sie zu Hause und unterwegs
df_total = pd.concat([df_home, df_away])
df_total
jfl_2020 = [
"Honda FC",
"Sony Sendai FC",
"Tokyo Musashino City FC",
"Tegevajaro Miyazaki",
"Honda Lock SC",
"Verspa Oita",
"FC Osaka",
"MIO Biwako Shiga",
"Viatin Mie",
"FC Maruyasu Okazaki",
"Suzuka Point Getters",
"Line Mail Aomori",
"Nara Club",
"Matsue City FC",
"Iwaki FC",
"Kochi United SC",
]
df_total
df_total["Ergebnis"] = df_total.apply(
lambda x: f'{x["Ergebnis"]}△{x["Zugegeben"]}'
if x["Ergebnis"] == x["Zugegeben"]
else f'{x["Ergebnis"]}○{x["Zugegeben"]}'
if x["Ergebnis"] > x["Zugegeben"]
else f'{x["Ergebnis"]}●{x["Zugegeben"]}',
axis=1,
)
df_total
#Schlachtrekordtabelle insgesamt
pv_senseki = df_total.pivot(values="Ergebnis", index=["Teamname", "Krieg"], columns="対Krieg相手").fillna("")
new_idx = pd.MultiIndex.from_product(
[jfl_2020, ["H", "A"]], names=pv_senseki.index.names
)
jfl_senseki = pv_senseki.reindex(new_idx, columns=jfl_2020)
jfl_senseki
print(jfl_senseki.to_markdown())
Honda FC | Sony Sendai FC | Tokyo Musashino City FC | Tegevajaro Miyazaki | Honda Lock SC | Verspa Oita | FC Osaka | MIO Biwako Shiga | Viatin Mie | FC Maruyasu Okazaki | Suzuka Point Getters | Line Mail Aomori | Nara Club | Matsue City FC | Iwaki FC | Kochi United SC | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
('Honda FC', 'H') | 1△1 | 3○1 | 1△1 | 1○0 | ||||||||||||
('Honda FC', 'A') | 4○0 | 3○0 | 1△1 | 1○0 | ||||||||||||
('Sony Sendai FC', 'H') | 0●4 | 1△1 | 3○1 | |||||||||||||
('Sony Sendai FC', 'A') | 0●2 | 4○2 | 2○1 | 2○0 | 1●2 | |||||||||||
('Tokyo Musashino City FC', 'H') | 2○0 | 1●2 | 2○1 | |||||||||||||
('Tokyo Musashino City FC', 'A') | 1△1 | 0●1 | 1△1 | |||||||||||||
('Tegevajaro Miyazaki', 'H') | 1△1 | 1●2 | 2○0 | |||||||||||||
('Tegevajaro Miyazaki', 'A') | 2○1 | 4○1 | 0△0 | 1○0 | ||||||||||||
('Honda Lock SC', 'H') | 0●3 | 1●2 | 0●4 | 0●3 | ||||||||||||
('Honda Lock SC', 'A') | 1△1 | 3○1 | 2○1 | 1○0 | ||||||||||||
('Verspa Oita', 'H') | 2●4 | 1○0 | 1●2 | 4○1 | ||||||||||||
('Verspa Oita', 'A') | 2○1 | 2○0 | 2○1 | |||||||||||||
('FC Osaka', 'H') | 1△1 | 1○0 | 1●2 | 0△0 | 2○1 | |||||||||||
('FC Osaka', 'A') | 1●2 | 4○0 | 2●3 | |||||||||||||
('MIO Biwako Shiga', 'H') | 1●4 | 3△3 | 6○0 | 1○0 | ||||||||||||
('MIO Biwako Shiga', 'A') | 1●3 | 0●1 | 2○1 | 3○1 | ||||||||||||
('Viatin Mie', 'H') | 0△0 | 0●2 | 1●2 | 3○2 | ||||||||||||
('Viatin Mie', 'A') | 1△1 | 2○1 | 0●1 | 1●2 | ||||||||||||
('FC Maruyasu Okazaki', 'H') | 1●2 | 1●3 | 1△1 | 0●2 | ||||||||||||
('FC Maruyasu Okazaki', 'A') | 0●1 | 0△0 | 2●3 | 2○0 | ||||||||||||
('Suzuka Point Getters', 'H') | 0●1 | 1○0 | 0●1 | 1●2 | 1○0 | |||||||||||
('Suzuka Point Getters', 'A') | 3△3 | 1○0 | 2△2 | |||||||||||||
('Line Mail Aomori', 'H') | 0●2 | 3○0 | 1△1 | |||||||||||||
('Line Mail Aomori', 'A') | 0●1 | 2○1 | 0●6 | 1△1 | ||||||||||||
('Nara Club', 'H') | 1●2 | 1○0 | 0●1 | 1△1 | ||||||||||||
('Nara Club', 'A') | 1△1 | 2○1 | 3○0 | 1●2 | ||||||||||||
('Matsue City FC', 'H') | 2○1 | 1●3 | 2○1 | 2○1 | ||||||||||||
('Matsue City FC', 'A') | 0●2 | 1●2 | 0●1 | 2○1 | 0●3 | |||||||||||
('Iwaki FC', 'H') | 1●2 | 3○2 | 2○1 | 4○3 | ||||||||||||
('Iwaki FC', 'A') | 1●4 | 2○0 | 0●1 | 1△1 | ||||||||||||
('Kochi United SC', 'H') | 1△1 | 0●1 | 0●2 | 2△2 | ||||||||||||
('Kochi United SC', 'A') | 1●3 | 1△1 | 1●2 | 3●4 |