Michaël Hooreman mic...@hooreman.be - http://www.hooreman.be
--
You received this message because you are subscribed to the Google Groups "PyData" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pydata+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
If you have a recent pandas, you can do this a bit simpler with the following:This gives:
data = pd.DataFrame(np.random.randn(10, 5), columns=('0_n', '1_n', '0_p', '1_p', 'x'))
data.columns = data.columns.str.split('_', expand=True)
data.columns = data.columns.swaplevel(1,0)
In [11]: data
Out[11]:
n p NaN
0 1 0 1 x
0 0.882079 -0.167304 -0.081573 -0.607486 -0.907488
1 -0.600067 0.285092 -1.592314 -0.049510 -1.050059
2 1.309180 -0.149241 0.428812 -2.046242 -0.141231
...
If you have a recent pandas, you can do this a bit simpler with the following:This gives:
data = pd.DataFrame(np.random.randn(10, 5), columns=('0_n', '1_n', '0_p', '1_p', 'x'))
data.columns = data.columns.str.split('_', expand=True)
data.columns = data.columns.swaplevel(1,0)
In [11]: data
Out[11]:
n p NaN
0 1 0 1 x
0 0.882079 -0.167304 -0.081573 -0.607486 -0.907488
1 -0.600067 0.285092 -1.592314 -0.049510 -1.050059
2 1.309180 -0.149241 0.428812 -2.046242 -0.141231
...
def split_cols(df, split_char, names=None):
new = df.copy()
new.columns =
df.columns.str.split(split, expand=True) # broken chain
--
You received this message because you are subscribed to the Google Groups "PyData" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pydata+unsubscribe@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to pydata+un...@googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "PyData" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pydata+un...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to pydata+unsubscribe@googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "PyData" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pydata+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "PyData" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pydata+unsubscribe@googlegroups.com.
top 0 1 0 1 0 bottom n n p p x 0 0.592875 -0.672805 0.717177 0.332351 -1.046899 1 1.273643 -0.966496 0.288252 -0.792620 -0.524999 2 0.979101 -0.097374 0.237005 -0.117168 -2.508691
To unsubscribe from this group and stop receiving emails from it, send an email to pydata+un...@googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "PyData" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pydata+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "PyData" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pydata+un...@googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "PyData" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pydata+un...@googlegroups.com.