在python

时间:2017-07-11 09:24:09

标签: python import-from-csv

我已将AWS的结算报告以CSV格式下载到我的服务器上。现在,我必须在python中解析这些CSV文件,以便它显示每天/每周/每月的合并/个人成本信息。 有人可以帮我这个吗?

import csv 
with open('588399947422-aws-billing-detailed-line-items-2015-09.c‌​sv') as csvfile: 
    readCSV = csv.reader(csvfile,delimiter=',') 
    for row in readCSV : 
        print row

CSV标头

"InvoiceID","PayerAccountId","LinkedAccountId","RecordType",‌​"RecordId","ProductN‌​ame","RateId","Subsc‌​riptionId","PricingP‌​lanId","UsageType","‌​Operation","Availabi‌​lityZone","ReservedI‌​nstance","ItemDescri‌​ption","UsageStartDa‌​te","UsageEndDate","‌​UsageQuantity","Blen‌​dedRate","BlendedCos‌​t","UnBlendedRate","‌​UnBlendedCost","Reso‌​urceId","user:Applic‌​ation Name","user:Business Unit"

1 个答案:

答案 0 :(得分:0)

使用内置<div class="line"> <div class="arrow"> <div class="pin"> </div> <div class="pin"> </div> </div> </div>模块。

来自docs:

csv

首先,您必须打开>>> import csv >>> with open(path_to_your_file, 'rb') as csvfile: ... reader = csv.reader(csvfile, delimiter=',', quotechar='|') ... for row in reader: # iterate over reader line by line (line is a list of values in this case) ... print row # list of values ,最好的选择是使用csv

然后,实例化with open(filename,'rb') as f: - 您必须指定分隔符(在大多数情况下为逗号)和quotechar(如果有的话,则为引号)。

然后你可以逐行迭代读者。