python - How can I join columns in Pandas? -


i´ve got following data frame:

      ident   year   month   day   hour   min    xxxx   yyyy  gps   snr        0         0   2015       5    13      5     0  20.45     16          0    44    1         0   2015       5    13      4     0  20.43     16          0    44    2         0   2015       5    13      3     0  20.42     16          0    44    3         0   2015       5    13      2     0  20.47     16          0    40    4         0   2015       5    13      1     0  20.50     16          0    44    5         0   2015       5    13      0     0  20.54     16          0    44    6         0   2015       5    12     23     0  20.56     16          0    40    

it comes csv file , i´d made dataframe using python pandas.

now i´d join columns year+month+day+hour+min make new one, example

date-time     2015-5-13-5-0  

how can ?

date_cols = ['year','month','day','hour','min'] df[date_cols] = df[date_cols].astype(str) df['the_date'] = df[date_cols].apply(lambda x: '-'.join(x),axis=1) 

output:

   ident  year month day hour min   xxxx  yyyy  gps  snr        the_date 0      0  2015     5  13    5   0  20.45    16    0   44   2015-5-13-5-0 1      0  2015     5  13    4   0  20.43    16    0   44   2015-5-13-4-0 2      0  2015     5  13    3   0  20.42    16    0   44   2015-5-13-3-0 3      0  2015     5  13    2   0  20.47    16    0   40   2015-5-13-2-0 4      0  2015     5  13    1   0  20.50    16    0   44   2015-5-13-1-0 5      0  2015     5  13    0   0  20.54    16    0   44   2015-5-13-0-0 6      0  2015     5  12   23   0  20.56    16    0   40  2015-5-12-23-0 

Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -