# based on code provided by Jeff Reback at PyCon 2015 in MontrealfrompandasimportTimestampimportnumpyasnpfrompandas.utilimporttestingdf=testing.makeMixedDataFrame()df.iloc[0]=np.nanblocks=df._data.blocksncols=sum(b.shape[0]forbinblocks)data=[None]*ncolsforbinblocks:# convert blocks into lists with conversion of datetimes# expands contiguous blocksifb.dtype.type==np.datetime64:# cast to timestamp, direct conversion to serial might be preferablevalues=np.array([Timestamp(v)forvinb.values.ravel()])values=values.reshape(b.shape)else:values=b.valuesresult=values.tolist()forcol_loc,colinzip(b.mgr_locs,result):data[col_loc]=colforiindf.index:row=[data[j][i]forjinrange(ncols)]# could be appended to an openpyxl worksheet
Comments (1)
Paul Symonds
Can you give an example of how to use this and also is it possible to append to openpyxl sheet at a given cell?
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.
Can you give an example of how to use this and also is it possible to append to openpyxl sheet at a given cell?