有兩種讀取資料的方法,
方法一(不推薦):
不推薦原因: 有可能一開始資料就複製不完整,同樣提供Python程式碼。
小檔案供一開始讀檔測試:
完整檔案供讀檔測試(事實上並不完整,因網頁複製沒有複製完整):
# -*- coding: utf-8 -*-
"""
Created on Thu Sep 15 14:40:21 2022
@author: meatbro
"""
import pandas as pd
my_file = open("temple_info.txt", "r",encoding="utf-8")
content = my_file.read()
content2 = content.split(' ')
content3 = list()
for i in content2:
try:
if(int(i)>=1746804 and int(i) <=1762755):
content3.append(int(i))
else:
content3.append(i)
except Exception:
content3.append(i)
w, h = 14, 8378
temple_info = [[0 for x in range(w)] for y in range(h)]
count = 0
renew = 0
for i in range(len(content3)):
if(i==0):
if(isinstance(content3[i], int)==True):
temple_info[count][0] = content3[i]
renew = 0
elif(isinstance(content3[i], int)==False):
renew = renew+1
temple_info[count][renew] = content3[i]
else:
if(isinstance(content3[i], int)==True):
temple_info[count][0] = content3[i]
renew = 0
count = count+1
elif(isinstance(content3[i], int)==False):
renew = renew+1
temple_info[count][renew] = content3[i]
temple_info = pd.DataFrame(temple_info)
temple_info = temple_info.iloc[: , 1:]
temple_info.to_excel("temple_info.xlsx")
方法二(推薦):
推薦原因: 速度極快,且不須再自己整理資料。