11,990
社区成员
发帖
与我相关
我的任务
分享
import pandas as pd
df = pd.DataFrame()
url_list = ['http://www.espn.com/nba/salaries/_/seasontype/4']
for i in range(2, 13):
url = 'http://www.espn.com/nba/salaries/_/page/%s/seasontype/4' % i
url_list.append(url)
#遍历网页中的table读取网页表格数据
for url in url_list:
df = df.append(pd.read_html(url), ignore_index=True)
#列表解析:遍历dataframe第3列,以子字符串$开头
df = df[[x.startswith('$') for x in df[3]]]
print(df)
df.to_csv('NBA.csv',header=['RK','NAME','TEAM','SALARY'], index=False)
运行后出错,提示如下:
D:\Python\pythonProject\venv\Scripts\python.exe "D:/Admin/Python数据分析从入门到精通/1. 示例源码--Python数据分析从入门到精通/03/18/demo.py"
D:\Admin\Python数据分析从入门到精通\1. 示例源码--Python数据分析从入门到精通\03\18\demo.py:9: FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead.
df = df.append(pd.read_html(url), ignore_index=True)
D:\Admin\Python数据分析从入门到精通\1. 示例源码--Python数据分析从入门到精通\03\18\demo.py:9: FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead.
df = df.append(pd.read_html(url), ignore_index=True)
D:\Admin\Python数据分析从入门到精通\1. 示例源码--Python数据分析从入门到精通\03\18\demo.py:9: FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead.
df = df.append(pd.read_html(url), ignore_index=True)
D:\Admin\Python数据分析从入门到精通\1. 示例源码--Python数据分析从入门到精通\03\18\demo.py:9: FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead.
df = df.append(pd.read_html(url), ignore_index=True)
D:\Admin\Python数据分析从入门到精通\1. 示例源码--Python数据分析从入门到精通\03\18\demo.py:9: FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead.
df = df.append(pd.read_html(url), ignore_index=True)
D:\Admin\Python数据分析从入门到精通\1. 示例源码--Python数据分析从入门到精通\03\18\demo.py:9: FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead.
df = df.append(pd.read_html(url), ignore_index=True)
D:\Admin\Python数据分析从入门到精通\1. 示例源码--Python数据分析从入门到精通\03\18\demo.py:9: FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead.
df = df.append(pd.read_html(url), ignore_index=True)
D:\Admin\Python数据分析从入门到精通\1. 示例源码--Python数据分析从入门到精通\03\18\demo.py:9: FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead.
df = df.append(pd.read_html(url), ignore_index=True)
D:\Admin\Python数据分析从入门到精通\1. 示例源码--Python数据分析从入门到精通\03\18\demo.py:9: FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead.
df = df.append(pd.read_html(url), ignore_index=True)
D:\Admin\Python数据分析从入门到精通\1. 示例源码--Python数据分析从入门到精通\03\18\demo.py:9: FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead.
df = df.append(pd.read_html(url), ignore_index=True)
D:\Admin\Python数据分析从入门到精通\1. 示例源码--Python数据分析从入门到精通\03\18\demo.py:9: FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead.
df = df.append(pd.read_html(url), ignore_index=True)
D:\Admin\Python数据分析从入门到精通\1. 示例源码--Python数据分析从入门到精通\03\18\demo.py:9: FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead.
df = df.append(pd.read_html(url), ignore_index=True)
Empty DataFrame
Columns: [0, 1, 2, 3]
Index: []