furas

convert string

Aug 6th, 2018
101
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 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'''
  2.  
  3. items = dict(item.split('=') for item in data.split(';'))
  4.  
  5. #print(items)
  6.  
  7. import csv
  8.  
  9. headers = [
  10.     'TTMNPMGN',
  11.     'NLOW',
  12.     'TTMPRCFPS',                  
  13.     #  I skip the middle sections
  14.     'QLTD2EQ',
  15.     'NHIG',
  16. ]
  17.  
  18. with open('DATA.csv', 'w') as csvfile:
  19.     csvwriter = csv.writer(csvfile)#, delimiter=',', quotechar='"')
  20.  
  21.     csvwriter.writerow(headers)
  22.  
  23.     # use headers to get values in correct order
  24.     row = [items.get(key, None) for key in headers]
  25.        
  26.     csvwriter.writerow(row)
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×