I am having a problem with changing the title bar in an existing DataFrame using pandas in python. After importing pandas and the csv file, I set the title bar to None to be able to remove duplicate dates after transposition. However, this leaves me with a row heading (and actually an index column) that I don't want.
df = pd.read_csv(spreadfile, header=None)
df2 = df.T.drop_duplicates([0], take_last=True)
del df2[1]
indcol = df2.ix[:,0]
df3 = df2.reindex(indcol)
The above-mentioned unimaginable code, however, fails in two ways. The index column is now required, but all entries are now NaN. My understanding of python is still not enough to recognize what python is doing. The desired result below is what I need, any help would be greatly appreciated!
df2 before re-indexing:
0 2 3 4 5
0 NaN XS0089553282 XS0089773484 XS0092157600 XS0092541969
1 01-May-14 131.7 165.1 151.8 88.9
3 02-May-14 131 164.9 151.7 88.5
5 05-May-14 131.1 165 151.8 88.6
7 06-May-14 129.9 163.4 151.2 87.1
df2 after reindexing:
0 2 3 4 5
0
NaN NaN NaN NaN NaN NaN
01-May-14 NaN NaN NaN NaN NaN
02-May-14 NaN NaN NaN NaN NaN
05-May-14 NaN NaN NaN NaN NaN
06-May-14 NaN NaN NaN NaN NaN
df2:
XS0089553282 XS0089773484 XS0092157600 XS0092541969
01-May-14 131.7 165.1 151.8 88.9
02-May-14 131 164.9 151.7 88.5
05-May-14 131.1 165 151.8 88.6
06-May-14 129.9 163.4 151.2 87.1