【发布时间】:2022-11-16 23:38:02
【问题描述】:
我是 jupyter notebook 和 python 的新手。最近我正在使用这段代码,但我找不到问题所在。我想将 "Tesla Quarterly Revenue(Millions of US $)" and "Tesla Quarterly Revenue(Millions of US $).1" 重命名为 "Data" and "Revenue" 但它没有改变。这是我的代码:
!pip install pandas
!pip install requests
!pip install bs4
!pip install -U yfinance pandas
!pip install plotly
!pip install html5lib
!pip install lxml
import yfinance as yf
import pandas as pd
import requests
from bs4 import BeautifulSoup
import plotly.graph_objects as go
from plotly.subplots import make_subplots
url = "https://www.macrotrends.net/stocks/charts/TSLA/tesla/revenue?utm_medium=Exinfluencer&utm_source=Exinfluencer&utm_content=000026UJ&utm_term=10006555&utm_id=NA-SkillsNetwork-Channel-SkillsNetworkCoursesIBMDeveloperSkillsNetworkPY0220ENSkillsNetwork23455606-2022-01-01"
html_data = requests.get(url).text
soup = BeautifulSoup(html_data, 'html5lib')
tesla_revenue = pd.read_html(url, match = "Tesla Quarterly Revenue")[0]
tesla_revenue = tesla_revenue.rename(columns={"Tesla Quarterly Revenue(Millions of US $)":"Date","Tesla Quarterly Revenue(Millions of US $).1":"Revenue"})
tesla_revenue.head()
这是输出:
【问题讨论】:
标签: python pip jupyter-notebook data-science jupyter