我在运行以下代码时出现此错误:
ValueError: If using all scalar values, you must pass an index
txt文件中有9000条记录。可能是因为记录太多了吗
import sqlalchemy as sa
import psycopg2
import requests as rq
import pandas as pd
import json
import time
import io
start_time = time.time()
while True:
temp = pd.DataFrame()
df = pd.DataFrame()
with open("vehicle_all_bus.txt", encoding="utf-8") as file:
fileList = [line.strip() for line in file]
for ids in fileList:
r = rq.get('https://api.tfl.gov.uk/Vehicle/' + ids + '/Arrivals')
r = r.text
temp = pd.read_json(r)
temp['Type'] = 'ids'
df = pd.concat([df, temp], sort=False).reset_index(drop=True)
engine = sa.create_engine('postgresql+psycopg2://postgres:3434@127.0.0.1/postgres')
df['timing'] = list(map(lambda x: json.dumps(x), df['timing']))
df.to_sql('tfl_all_bus_data2', engine, if_exists='append', index=False)
time.sleep(60)
目前没有回答
相关问题 更多 >
编程相关推荐