为什么我的csv编写器在列中写入而不是行?

时间:2016-01-12 15:15:59

标签: python excel csv

我的csv编写器是在列中写入而不是在行,我做错了什么? Python 3.5代码:

def create_csv(finished_file):
    csv_data = []
    header = ["Parcel Number"]
    csv_data.append(header)
    csv_data.append(parcel_codes)
    resultFile = open(finished_file+".csv",'w+')
    wr = csv.writer(resultFile)
    wr.writerows(csv_data)
    resultFile.close()

以前工作 - 我确实升级到excel 2016,但这不应该有所作为。并且想到这一点我改为Anaconda,但我认为这也不重要。

任何想法或帮助都会很棒!

根据要求,这是打印时的parcel_codes:

['DP00360000 0028', 'DP00360000 0036', 'DP00360000 0027', 'DP00360000 0037', 'DP00360000 0026', 'DP00360000 0038', 'Keller, Mark A; Keller, Jennifer R.', 'DP00360000 0025', 'DP00360000 0024', 'DP00360000 0011', 'DP00360000 0023', 'DP00360000 0012', 'DP00360000 0022', 'DP00360000 0013', 'DP00360000 0021', 'DP00360000 0014', 'DP00360000 0020', 'DP00360000 0015', 'DP00360000 0019', 'DP00360000 0016', 'DP00360000 0018', 'DP00360000 0017', 'DP00360000 0049', 'DP00360000 0048', 'DP00360000 0050', 'Sapp (Family Trust)', 'DP00360000 0047', 'DP00360000 0051', 'DP00360000 0046', 'DP00360000 0052', 'DP00360000 0045', 'DP00360000 0053', 'DP00360000 0044', 'DP00360000 0054', 'DP00360000 0043', 'DP00360000 0055', 'DP00360000 0042', 'DP00360000 0056', 'DP00360000 0041', 'DP00360000 0057', 'DP00360000 0040', 'DP00360000 0058', 'DP00360000 0039', 'DP00360000 0059', 'DP00360000 0060', 'DP00360000 0008', 'DP00360000 0061', 'DP00360000 0007', 'DP00360000 0002', 'DP00360000 0006', 'DP00360000 0003', 'DP00360000 0005', 'DP00360000 0004', 'DP00330000 0076', 'DP00330000 0077', 'DP00330000 0078', 'DP00330000 0004', 'DP00330000 0079', 'DP00330000 0005', 'DP00330000 0080', 'DP00330000 0081', 'DP00330000 0082', 'DP00360000 0187', 'DP00360000 0186', 'DP00360000 0225', 'DP00360000 0226', 'DP00360000 0185', 'DP00360000 0227', 'DP00360000 0228', 'DP00360000 0184', 'DP00360000 0229', 'DP00360000 0183', 'DP00360000 0230', 'DP00360000 0182', 'DP00360000 0231', 'DP00360000 0181', 'DP00360000 0232', 'DP00360000 0T0J', 'DP00360000 0180', 'DP00360000 0233', 'DP00360000 0179', 'DP00360000 0234', 'DP00360000 0178', 'DP00360000 0235', 'DP00360000 0177', 'DP00360000 0072', 'DP00360000 0176', 'DP00360000 0175', 'DP00360000 0071', 'DP00360000 0073', 'DP00360000 0070', 'DP00360000 0074', 'DP00360000 0069', 'DP00360000 0075', 'DP00360000 0068', 'DP00360000 0076', 'DP00360000 0067', 'DP00360000 0077', 'Andrew, Henry A; Andrew, Erika C.', 'Andrew, Henry A; Andrew, Erika C.']

1 个答案:

答案 0 :(得分:0)

在您的示例中,writerowscsv_data解释为要写入的行列表,而不是单行。您可以使用writerowwr.writerows([csv_data])来解决此问题。