how can I drop a level in multi-indexed columns when converting three columns to datetime? Below example only contains three columns while in my dateframe there are more columns, of course, and those other columns use two level names.
>>> import pandas as pd
>>> df = pd.DataFrame([[2010, 1, 2],[2011,1,3],[2012,2,3]])
>>> df.columns = [['year', 'month', 'day'],['y', 'm', 'd']]
>>> print(df)
year month day
y m d
0 2010 1 2
1 2011 1 3
2 2012 2 3
>>> pd.to_datetime(df[['year', 'month', 'day']])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python2.7/site-packages/pandas/core/tools/datetimes.py", line 512, in to_datetime
result = _assemble_from_unit_mappings(arg, errors=errors)
File "/usr/lib64/python2.7/site-packages/pandas/core/tools/datetimes.py", line 582, in _assemble_from_unit_mappings
unit = {k: f(k) for k in arg.keys()}
File "/usr/lib64/python2.7/site-packages/pandas/core/tools/datetimes.py", line 582, in <dictcomp>
unit = {k: f(k) for k in arg.keys()}
File "/usr/lib64/python2.7/site-packages/pandas/core/tools/datetimes.py", line 577, in f
if value.lower() in _unit_map:
AttributeError: 'tuple' object has no attribute 'lower'
Edit: Add more columns to explain better:
>>> df = pd.DataFrame([[2010, 1, 2, 10, 2],[2011,1,3,11,3],[2012,2,3,12,2]])
>>> df.columns = [['year', 'month', 'day', 'temp', 'wind_speed'],['', '', '', 'degc','m/s']]
>>> print(df)
year month day temp wind_speed
degc m/s
0 2010 1 2 10 2
1 2011 1 3 11 3
2 2012 2 3 12 2
What I need is to combine first three columns to datetime index, leaving two last columns with data.