python - Exporting superscript notation in pandas dataframe to csv or excel -


i write foll. csv file:

  df.loc[0] = ['total (2000)',                        numpy.nan,                        numpy.nan,                        numpy.nan,                        2.0,                        1.6,                        '10^6 km^2'] 

is there way while writing '10^6 km^2' in format such 6 superscript 10 , 2 superscript km. if not possible in csv, can export excel?

one possible way change actual contents of dataframe before writing csv (but can automate somewhat).

as proof of concept, using '\u2076' unicode representation of superscript 6:

in [21]: df out[21]:                  b   c   d  e    f          g 0  total (2000) nan nan nan  2  1.6  10^6 km^2  in [30]: df['g'] = (df['g'].str.replace("10\^6", u"10\u2076")     ...:                   .str.replace("km\^2", u"km\u00b2"))  in [31]: df out[31]:                  b   c   d  e    f        g 0  total (2000) nan nan nan  2  1.6  10⁶ km²  in [32]: print df.to_csv(encoding='utf-8', index=false) a,b,c,d,e,f,g total (2000),,,,2.0,1.6,10⁶ km² 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -