import pandas as pd
pd.plotting.register_matplotlib_converters()
import matplotlib.pyplot as plt
%matplotlib inline
import seaborn as sns
print("Setup Complete")
Setup Complete
可以使用pd.read_csv
来读取csv档案
# Path of the file to read
spotify_filepath = "./spotify.csv"
# Read the file into a variable spotify_data
spotify_data = pd.read_csv(spotify_filepath, index_col="Date", parse_dates=True)
使用head()
可以看到前5笔资料
spotify_data.head()
若要印出最後5笔资料,可以使用tail()
spotify_data.tail()
现在我们已经有资料了,只需要一行就可以将资料转为图表
# Line chart showing daily global streams of each song
sns.lineplot(data=spotify_data)
<AxesSubplot:xlabel='Date'>
sns.lineplot
代表说要使用line chart
data=spotify_data
可以选择要使用的资料
若要设定图表的宽度及高度,或是图表的title,可以使用以下的方法
# Set the width and height of the figure
plt.figure(figsize=(14,6))
# Add title
plt.title("Daily Global Streams of Popular Songs in 2017-2018")
# Line chart showing daily golbal streams of each song
sns.lineplot(data=spotify_data)
<AxesSubplot:title={'center':'Daily Global Streams of Popular Songs in 2017-2018'}, xlabel='Date'>
)
我们可以先去找出有那些column可以用
list(spotify_data.columns)
['Shape of You',
'Despacito',
'Something Just Like This',
'HUMBLE.',
'Unforgettable']
选择Shpae of You
跟Despacito
来绘制line chart
# Set the width and height of the figure
plt.figure(figsize=(14,6))
# Add title
plt.title("Daily Global Streams of Popular Songs in 2017-2018")
# Line chart showing daily global streams of 'Shape of You'
sns.lineplot(data=spotify_data['Shape of You'], label="Shape of You")
# Line chart showing daily global streams of 'Despacito'
sns.lineplot(data=spotify_data['Despacito'], label="Despacito")
# Add label for horizontal axis
plt.xlabel("Date")
Text(0.5, 0, 'Date')
<<: [从0到1] C#小乳牛 练成基础程序逻辑 Day 18 - do while回圈 作用域 break + continue
本篇介绍 ES2021 (ES12) 提供的 String.prototype.replaceAl...
今日题目 题目连结:53. Maximum Subarray 题目主题:Array, Divide ...
Golang OAuth 2.0 在一开始的开赛目标就是希望可以完成golang + OAuth 2...
Agenda 资安宣言 测试环境与工具 技术原理与程序码 References 下期预告 资安宣言 ...
回到村子後,山姆变成了斜杠青年,他将探险的故事写成了一本书。 书的封面印着山姆的肖像。 而书名就叫...