Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- data = '''TTMNPMGN=31.28954;NLOW=307.97567;TTMPRCFPS=27.16872;TTMGROSMGN=49.10444;TTMCFSHR=13.00898;QCURRATIO=1.20643;TTMREV=301399.3;TTMINVTURN=486.1752;TTMOPMGN=38.86435;TTMPR2REV=11.19504;AEPSNORM=7.57146;TTMNIPEREM=2105243;EPSCHNGYR=60.0117;TTMPRFCFPS=29.49287;TTMRECTURN=15.61345;TTMPTMGN=38.10252;QCSHPS=17.31687;TTMFCF=114406.6;LATESTADATE=2017-12-31;APTMGNPCT=37.10254;AEBTNORM=89233.92;TTMNIAC=92496.23;NetDebt_I=16365.67;PRYTDPCTR=-8.26516;TTMEBITD=118195.1;AFEEPSNTM=8.9858;PR2TANBK=12.3999;EPSTRENDGR=40.56326;QTOTD2EQ=56.58907;TTMFCFSHR=11.98382;QBVPS=33.64562;NPRICE=345;YLD5YAVG=0.25561;REVTRENDGR=40.19977;TTMEPSXCLX=9.68724;QTANBVPS=28.64635;PRICE2BK=10.25394;MKTCAP=3374178;TTMPAYRAT=0;TTMINTCOV=-99999.99;TTMDIVSHR=0.88;TTMREVCHG=54.42107;TTMROAPCT=15.60043;TTMROEPCT=34.0467;TTMREVPERE=6728263;APENORM=45.56584;TTMROIPCT=22.18601;REVCHNGYR=48.38553;CURRENCY=CNY;DIVGRPCT=56.26752;TTMEPSCHG=72.78667;PEEXCLXOR=35.61385;QQUICKRATI=1.2046;TTMREVPS=31.57088;BETA=1.10179;TTMEBT=114840.7;ADIV5YAVG=0.47269;ANIACNORM=72201.45;QLTD2EQ=49.80237;NHIG=476.6'''
- items = dict(item.split('=') for item in data.split(';'))
- #print(items)
- import csv
- headers = [
- 'TTMNPMGN',
- 'NLOW',
- 'TTMPRCFPS',
- # I skip the middle sections
- 'QLTD2EQ',
- 'NHIG',
- ]
- with open('DATA.csv', 'w') as csvfile:
- csvwriter = csv.writer(csvfile)#, delimiter=',', quotechar='"')
- csvwriter.writerow(headers)
- # use headers to get values in correct order
- row = [items.get(key, None) for key in headers]
- csvwriter.writerow(row)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement