Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to realize NBA player salary ranking by R data Visualization

Shulou Source: shulou.com Published: 2022-06-01 20:20:03 11月17日 Update

This article mainly introduces "how to realize NBA player salary ranking with R data Visualization". In daily operation, I believe many people have doubts about how to realize NBA player salary ranking with R data Visualization. The editor has consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about how R data Visualization can achieve NBA player salary ranking! Next, please follow the editor to study!

Import math

Import requests

From bs4 import BeautifulSoup

Headers = {"User-Agent": 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36'}

Fw = open ('NBA_salary_3.txt','w')

Fw.write ('% s\ t% s\ n%) ("year", "rk", "player", "position", "team", "salary"))

Years = list (range (2000)

For year in years:

URL = "http://www.espn.com/nba/salaries/_/year/" + str (year)

Print (URL)

Page = requests.get (URL,headers=headers)

Soup = BeautifulSoup (page.content,'html.parser')

Df = soup.find_all ('tr')

J = 0

For aa in df:

J = j + 1

If j = = 1:

Continue

Elif j > 1 and j < 12:

All_td = aa.find_all ('td')

Rk = all_td [0] .get _ text ()

Player_position = all_td [1] .get _ text ()

# print (player_position)

Player = player_position.split (",") [0]

Position = player_position.split (",") [1]

Team = all_td [2] .get _ text ()

Salary = all_td [3] .get _ text () .replace ("$", ") .replace (", ",")

Fw.write ('% s\ t% s\ n%) (str (year), rk,player,position,team,salary))

Else:

Break

Fw.close ()

First of all, let's take a look at the 2020 salary ranking top10library (ggplot2).

Ggplot (df1,aes (xymrkjime)) +

Geom_col (aes (fill=player)) +

Geom_label (aes (label=paste0 (salary, "Wan"), hjust=1)) +

Theme_bw () +

Scale_x_continuous (breaks = 1 df1 10 labels = df1 $player) +

Coord_flip () + labs (x = "", y = "") +

Theme (legend.position = "none")

Image.png then makes a dynamic bar chart.

The tool used is the gganimate package in R language.

The code used is

Df

Tags: Rankings data players salary visualization learning and then more help practical code dynamic tools articles methods theories knowledge articles websites payroll Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Docker Xiaomi vpn NVidia