当我使用 python 将 csv 转换为 mysqldb 时,如何留下不必要的引号?
How to leave the unnecessary quotation marks when i convert a csv into a mysqldb with python?
我有一个 CSV excel 文件,我想将其转换成 mysqldb。
它工作得很好,但是在 MYSQLdb 的每个单元格中都有不必要的引号,像这样:""
.
当单元格为空时,我会看到:""
当单元格不为空时看到这个:"somethingdata"
我看不懂,csv文件里有none.
为什么要加引号
这是我的代码,我认为也是正确的。
connection = MySQLdb.connect(host='localhost',
user='root',
passwd='1234',
db='database')
cursor = connection.cursor()
query = """
CREATE TABLE `test` (
`Megnevezes` varchar(100) DEFAULT NULL,
`2015` varchar(100) DEFAULT NULL,
`2014` varchar(100) DEFAULT NULL,
`2013` varchar(100) DEFAULT NULL,
`2012` varchar(100) DEFAULT NULL,
`2011` varchar(100) DEFAULT NULL,
`ID` int(10) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=32 DEFAULT CHARSET=utf8"""
cursor.execute(query)
connection.commit()
cursor.close()
connection = MySQLdb.connect(host='localhost',
user='root',
passwd='1234',
db='database')
cursor = connection.cursor()
query = """ load data local infile 'C:/Python27/output.csv'
into table test
character set latin1
fields terminated by ';'
lines terminated by '\n'
ignore 1 lines;
"""
cursor.execute(query)
connection.commit()
cursor.close()
有什么办法可以解决这个问题吗?
https://dev.mysql.com/doc/refman/5.7/en/load-data.html
使用:ENCLOSED BY 'char'
其中 char 将是 "
我有一个 CSV excel 文件,我想将其转换成 mysqldb。
它工作得很好,但是在 MYSQLdb 的每个单元格中都有不必要的引号,像这样:""
.
当单元格为空时,我会看到:""
当单元格不为空时看到这个:"somethingdata"
我看不懂,csv文件里有none.
为什么要加引号这是我的代码,我认为也是正确的。
connection = MySQLdb.connect(host='localhost',
user='root',
passwd='1234',
db='database')
cursor = connection.cursor()
query = """
CREATE TABLE `test` (
`Megnevezes` varchar(100) DEFAULT NULL,
`2015` varchar(100) DEFAULT NULL,
`2014` varchar(100) DEFAULT NULL,
`2013` varchar(100) DEFAULT NULL,
`2012` varchar(100) DEFAULT NULL,
`2011` varchar(100) DEFAULT NULL,
`ID` int(10) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=32 DEFAULT CHARSET=utf8"""
cursor.execute(query)
connection.commit()
cursor.close()
connection = MySQLdb.connect(host='localhost',
user='root',
passwd='1234',
db='database')
cursor = connection.cursor()
query = """ load data local infile 'C:/Python27/output.csv'
into table test
character set latin1
fields terminated by ';'
lines terminated by '\n'
ignore 1 lines;
"""
cursor.execute(query)
connection.commit()
cursor.close()
有什么办法可以解决这个问题吗?
https://dev.mysql.com/doc/refman/5.7/en/load-data.html
使用:ENCLOSED BY 'char'
其中 char 将是 "