Combine two columns of text in pandas dataframe

后端 未结 18 1133
-上瘾入骨i
-上瘾入骨i 2020-11-22 01:32

I have a 20 x 4000 dataframe in Python using pandas. Two of these columns are named Year and quarter. I\'d like to create a variable called p

18条回答
  •  一生所求
    2020-11-22 01:49

    One can use assign method of DataFrame:

    df= (pd.DataFrame({'Year': ['2014', '2015'], 'quarter': ['q1', 'q2']}).
      assign(period=lambda x: x.Year+x.quarter ))
    

提交回复
热议问题