[英]Adding headers to comma delimited string using Python 3.4
I have a static output from a serial connection which is comma delimited. 我有一个以逗号分隔的串行连接的静态输出。 The incoming data will always have 23 values. 输入的数据将始终具有23个值。
data string from machine: 来自机器的数据字符串:
# "987654321 "," "," ", .00, .00, .30, .06, .35, .50, 2.00, .50, .00, .00, .00, .00, .00, .00, .00, .00, .00, .00, .00, 3.71 #“ 987654321”,“”,“” 、. 00,.00,.30,.06,.35,.50、2.00,.50,.00,.00,.00,.00,.00,.. 00,.00,.00,.00,.00,.00、3.71
import serial
con=serial.Serial('COM4',115200)
while 1:
if con.inWaiting():
val = con.read(con.inWaiting())
if len(val)> 1 :
stra = val.decode("utf-8")
I receive the data and can view the data to verify it's correct. 我收到了数据,可以查看数据以验证其正确性。 I'm lost when trying to add column header to the string so that data can be inserted into a database 尝试将列标题添加到字符串以使数据可以插入数据库时迷路了
I'm using a Raspberry Pi to run the program between the machine and database 我正在使用Raspberry Pi在计算机和数据库之间运行程序
The column headers: Batch ID, Sub ID, Grand ID, Value4, Value5, Dime, Penny, Nickel, Quarter, Dollar, Half, Value12, Value13, Value14, Value15, Value16, Value17, Value18, Value19, Value20, Value21, Value22, Total 列标题:批次ID,子ID,盛大ID,Value4,Value5,Dime,Penny,Nickel,Quarter,美元,Half,Value12,Value13,Value14,Value15,Value16,Value17,Value18,Value19,Value20,Value21,Value22 ,总计
The database on the Raspberry Pi will be MySQL which will be uploaded to SQL Sever when the unit is connected to the network Raspberry Pi上的数据库将是MySQL,当设备连接到网络时,该数据库将上传到SQL Sever。
You don't need any header in your CSV file while importing it into your MySQL. 将CSV文件导入MySQL时,不需要任何标题。 Actually, MySQL would not understand any header if you push that header to it, you would need to tell MySQL to skip that line anyway. 实际上,如果将标题推送到它,MySQL不会理解任何标题,您需要告诉MySQL无论如何都要跳过该行。
Just follow this manual: http://dev.mysql.com/doc/refman/5.1/en/load-data.html 只需遵循本手册即可: http : //dev.mysql.com/doc/refman/5.1/en/load-data.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.