我有一份列表A_str,其中包含有关公司名称和财务比率的信息。 现在我想要一个只有公司名称的新列表和一个包含所有比率的第二个列表。 到目前为止,我可以将列表拆分为“ - ”但我无法将这些新元素附加到新列表的“公司”和“比率”中。
A_str = ['Name',
'AMAZON.COM - TOT RETURN IND',
'AMAZON.COM INC - NET CASH FLOW - FINANCING',
'AMAZON.COM INC - NET CASH FLOW - INVESTING',
'AMAZON.COM INC - NET CASH FLOW-OPERATING ACTIVS',
'AMAZON.COM INC - COST OF GOODS SOLD (EXCL DEP)',
'AMAZON.COM INC - EARNINGS BEF INTEREST & TAXES',
'AMAZON.COM INC - EBIT & DEPRECIATION',
'AMAZON.COM INC - GROSS INCOME',
'AMAZON.COM INC - NET SALES OR REVENUES',
'AMAZON.COM INC - OPERATING INCOME',
'AMAZON.COM INC - NET INCOME AVAILABLE TO COMMON',
'AMAZON.COM INC - ACCOUNTS PAYABLE',
'AMAZON.COM INC - CASH',
"AMAZON.COM INC - COMMON SHAREHOLDERS' EQUITY",
'AMAZON.COM INC - CURRENT ASSETS - TOTAL',
'AMAZON.COM INC - CURRENT LIABILITIES-TOTAL',
'AMAZON.COM INC - TOTAL INVENTORIES',
'AMAZON.COM INC - LONG TERM DEBT',
'AMAZON.COM INC - TOTAL ASSETS']
for element in A_str:
company.append(element.split('-'))
print company
输出应如下所示:
company = [AMAZON.COM, AMAZON.COM INC, AMAZON.COM INC... AMATON.COM INC]
ratios = [TOT RETURN IND, NET CASH FLOW - FINANCING, NET CASH FLOW - INVESTING... TOTAL ASSETS]
答案 0 :(得分:0)
你可以简单地映射分割,过滤它是否大小为2元组,并将其压缩以分别获取值:
In[9]: l=['Name', 'AMAZON.COM - TOT RETURN IND', 'AMAZON.COM INC - NET CASH FLOW - FINANCING', 'AMAZON.COM INC - NET CASH FLOW - INVESTING', 'AMAZON.COM INC - NET CASH FLOW-OPERATING ACTIVS', 'AMAZON.COM INC - COST OF GOODS SOLD (EXCL DEP)', 'AMAZON.COM INC - EARNINGS BEF INTEREST & TAXES', 'AMAZON.COM INC - EBIT & DEPRECIATION', 'AMAZON.COM INC - GROSS INCOME', 'AMAZON.COM INC - NET SALES OR REVENUES', 'AMAZON.COM INC - OPERATING INCOME', 'AMAZON.COM INC - NET INCOME AVAILABLE TO COMMON', 'AMAZON.COM INC - ACCOUNTS PAYABLE', 'AMAZON.COM INC - CASH', "AMAZON.COM INC - COMMON SHAREHOLDERS' EQUITY", 'AMAZON.COM INC - CURRENT ASSETS - TOTAL', 'AMAZON.COM INC - CURRENT LIABILITIES-TOTAL', 'AMAZON.COM INC - TOTAL INVENTORIES', 'AMAZON.COM INC - LONG TERM DEBT', 'AMAZON.COM INC - TOTAL ASSETS']
In[22]: companies, ratios =zip(*filter( lambda y: len(y) == 2, map(lambda x: tuple(x.split(" - ")), l)))
In[23]: companies
Out[22]:
('AMAZON.COM',
'AMAZON.COM INC',
'AMAZON.COM INC',
'AMAZON.COM INC',
'AMAZON.COM INC',
'AMAZON.COM INC',
'AMAZON.COM INC',
'AMAZON.COM INC',
'AMAZON.COM INC',
'AMAZON.COM INC',
'AMAZON.COM INC',
'AMAZON.COM INC',
'AMAZON.COM INC',
'AMAZON.COM INC',
'AMAZON.COM INC',
'AMAZON.COM INC')
In[24]: ratios
Out[23]:
('TOT RETURN IND',
'NET CASH FLOW-OPERATING ACTIVS',
'COST OF GOODS SOLD (EXCL DEP)',
'EARNINGS BEF INTEREST & TAXES',
'EBIT & DEPRECIATION',
'GROSS INCOME',
'NET SALES OR REVENUES',
'OPERATING INCOME',
'NET INCOME AVAILABLE TO COMMON',
'ACCOUNTS PAYABLE',
'CASH',
"COMMON SHAREHOLDERS' EQUITY",
'CURRENT LIABILITIES-TOTAL',
'TOTAL INVENTORIES',
'LONG TERM DEBT',
'TOTAL ASSETS')
答案 1 :(得分:0)
拆分每个项目并压缩结果,省略标题元素:
var currentFile = null;
Dropzone.autoDiscover = false;
var myDropzone = new Dropzone("div#myDrop", {
addRemoveLinks: true,
url: "#",
maxFiles:1,
init: function() {
this.on("addedfile", function(file) {
if (currentFile) {
this.removeFile(currentFile);
}
currentFile = file;
});
}
});
如果你可以改变company, ratios = zip(*(item.split(' - ') for item in A_str[1:]))
,你可以改为弹出标题元素:
A_str