熊猫“ to_csv”无法设置引号

时间:2019-04-29 06:16:04

标签: python pandas

我正在尝试做here中的一些答案,但是当我设置

out.to_csv('somefile.txt', index=False, header=False, sep="\t",
           quoting=csv.QUOTE_NONE)

我收到错误NameError: name 'csv' is not defined。我在这里做错了什么?

我正在运行熊猫0.24.1

1 个答案:

答案 0 :(得分:1)

添加名称空间DECLARE @MAIN_TABLE TABLE ([ID_1] INT, [ID_2] INT, [ABC_VAL] INT, [KLM_VAL] INT, [XYZ_VAL] INT) insert @MAIN_TABLE values (10,100,NULL,NULL,NULL), (10,200,NULL,NULL,NULL), (30,300,NULL,NULL,NULL) DECLARE @REF_TABLE TABLE ([ID_1] INT, [ID_2] INT, [FLD_NAME] varchar(3),[FLD_VAL] INT) insert @REF_TABLE values (10,100,'ABC',11111), (10,100,'XYZ',22222), (10,100,'KLM',33333), (20,200,'ABC',88888), (30,300,'KLM',55555) SELECT * FROM @MAIN_TABLE SELECT * FROM @REF_TABLE UPDATE MT SET MT.ABC_VAL = B.ABC_VAL, MT.XYZ_VAL = B.XYZ_VAL, MT.KLM_VAL = B.KLM_VAL FROM @MAIN_TABLE MT INNER JOIN ( SELECT A.ID_1,A.ID_2, SUM(A.ABC_FLD_VAL) AS [ABC_VAL], SUM(A.XYZ_FLD_VAL) AS [XYZ_VAL], SUM(A.KLM_FLD_VAL) AS [KLM_VAL] FROM ( SELECT DISTINCT MT.ID_1,MT.ID_2, CASE WHEN rt.FLD_NAME = 'ABC' THEN FLD_VAL ELSE NULL END 'ABC_FLD_VAL', CASE WHEN rt.FLD_NAME = 'XYZ' THEN FLD_VAL ELSE NULL END 'XYZ_FLD_VAL', CASE WHEN rt.FLD_NAME = 'KLM' THEN FLD_VAL ELSE NULL END 'KLM_FLD_VAL' FROM @MAIN_TABLE MT INNER JOIN @REF_TABLE RT ON RT.ID_1 = MT.ID_1 AND RT.ID_2 = MT.ID_2 ) A GROUP BY A.ID_1,A.ID_2 ) B ON MT.ID_1 = B.ID_1 AND MT.ID_2 = B.ID_2 SELECT * FROM @MAIN_TABLE

csv

或设置值import csv out.to_csv('somefile.txt', index=False, header=False, sep="\t", quoting=csv.QUOTE_NONE) ,数字来自docs

  

引用:int或csv.QUOTE_ *实例,默认为0
  每个csv.QUOTE_ *常量的控制字段引用行为。使用QUOTE_MINIMAL(0),QUOTE_ALL(1),QUOTE_NONNUMERIC(2)或 QUOTE_NONE 3 )之一。

3