我的代码在Jupyter笔记本中有效,但是当我将其传输到.py文件时,出现错误: ValueError:无法将字符串转换为float:'2002-03'
这是df:
Season Team GP GS MPG FG% FT% BPG RPG APG PPG
0 1989–90 Seattle 81 1 13.8 .479 .736 0.9 4.3 0.3 6.5
1 1990–91 Seattle 81 66 30.1 .508 .661 1.5 8.4 1.8 15.0
2 1991–92 Seattle 64 23 28.3 .504 .748 1.9 10.4 1.3 15.5
3 1992–93 Seattle 78 68 33.1 .492 .712 1.9 10.7 2.0 17.8
4 1993–94 Seattle 79 73 32.9 .538 .741 2.1 10.8 2.6 18.1
5 1994–95 Seattle 82 79 32.7 .547 .749 1.5 10.9 1.8 18.7
6 1995–96 Seattle 79 76 33.3 .561 .742 1.6 11.4 2.2 19.6
7 1996–97 Seattle 81 75 34.0 .510 .742 1.0 10.0 1.9 18.7
8 1997–98 Cleveland 80 80 34.6 .445 .727 1.1 9.3 2.5 20.1
9 1998–99 Cleveland 42 42 35.1 .482 .789 1.1 9.2 2.4 20.5
10 1999–2000 Cleveland 82 82 30.4 .417 .776 1.2 8.8 1.7 17.8
11 2000–01 Portland 68 3 15.9 .407 .771 0.3 3.8 1.0 10.5
12 2001–02 Portland 75 5 16.4 .430 .794 0.4 3.8 0.7 8.1
13 2002–03 Orlando 79 55 20.7 .418 .742 0.4 5.7 0.7 6.8
PPG = [float(line) for line in df1.PPG]
plt.plot(df1.Season, PPG)
plt.xlabel(r'Seasons')
plt.ylabel(r'Avg Points Per Game')
plt.gcf().autofmt_xdate()
我想创建一个简单的以df.Season为x轴的线图