You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.8 KiB

import pandas as pd
import mysql.connector
df = pd.read_csv('igs_stations.csv', encoding='iso-8859-1')
# # 执行逐行插入数据操作
# for index, row in df.iterrows():
# print(row['Site Name'],row['Country/Region'],row['Receiver'],row['Antenna'],row['Radome'],
# row['Satellite System'],row['Latitude'],row['Longitude'],row['Height (m)'],row['X (m)'],
# row['Y (m)'],row['Z (m)'],row['Calibration'],row['Networks'],row['Data Center'],
# row['IERS DOMES'],row['Clock'],row['Agencies'],row['Last Data'])
# print(df.dtypes)
df = df.dropna()
# #
# 连接到 MySQL 数据库
conn = mysql.connector.connect(
host="localhost", # 数据库主机地址
user="root", # 数据库用户名
password="123123", # 数据库密码
database='shop'
)
# 创建一个游标对象
cursor = conn.cursor()
insert_query = "INSERT INTO igs_stations (Site_Name, Country_Region, Receiver,Antenna,Radome,Satellite_System,Latitude," \
"Longitude,Height_m,X_m,Y_m,Z_m,Calibration,Networks,Data_Center,IERS_DOMES,Clock,Agencies," \
"Last_Data) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"
for _, row in df.iterrows():
cursor.execute(insert_query, (row['Site Name'],row['Country/Region'],row['Receiver'],row['Antenna'],row['Radome'],
row['Satellite System'],row['Latitude'],row['Longitude'],row['Height (m)'],row['X (m)'],
row['Y (m)'],row['Z (m)'],row['Calibration'],row['Networks'],row['Data Center'],
row['IERS DOMES'],row['Clock'],row['Agencies'],row['Last Data']))
# 提交更改
conn.commit()
# 关闭连接
conn.close()