wb = load_workbook("Top 10 most Streamed.xlsx")
ws = wb.active
for row in ws.rows:
for cell in row:
print(cell.value, end= " ")
print()
wb.close()
wb = load_workbook("Top 10 most Streamed.xlsx")
ws = wb.active
for column in ws.columns:
for cell in column:
print(cell.value, end= " ")
print()
wb.close()
利用欄和列座標來讀取指定儲存格的資料
ws = wb['Top 10 most Streamed']
v = ws["A1"].value
print("A1: ", v)
v = ws["B1"].value
print("B1: ", v)
v = ws["C1"].value
print("C1: ", v)
wb.close()
心得:
今天學習了如何用python讀取現有的excel資料表,我在kaggle上找了一筆比較有興趣的Dataset「Top 100 most streamed songs on spotify」來當例子練習,利用今天學到的一些方法可以幫助我們整理出想看到的特定內容。
** Top 100 most streamed songs on spotify**
原網址:https://www.kaggle.com/pavan9065/top-100-most-streamed-songs-on-spotify/version/1
(方便呈現完整的畫面,所以今天練習的例子只有取原檔案的前十筆資料)