我已将AWS的结算报告以CSV格式下载到我的服务器上。现在,我必须在python中解析这些CSV文件,以便它显示每天/每周/每月的合并/个人成本信息。 有人可以帮我这个吗?
import csv
with open('588399947422-aws-billing-detailed-line-items-2015-09.csv') as csvfile:
readCSV = csv.reader(csvfile,delimiter=',')
for row in readCSV :
print row
CSV标头
"InvoiceID","PayerAccountId","LinkedAccountId","RecordType","RecordId","ProductName","RateId","SubscriptionId","PricingPlanId","UsageType","Operation","AvailabilityZone","ReservedInstance","ItemDescription","UsageStartDate","UsageEndDate","UsageQuantity","BlendedRate","BlendedCost","UnBlendedRate","UnBlendedCost","ResourceId","user:Application Name","user:Business Unit"
答案 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(如果有的话,则为引号)。
然后你可以逐行迭代读者。