データフレームがあります。 他の列の条件を使用して列を追加する方法
if 'month'=1,2,3 the elements = 'term1'
'month'=4,5 the elements = 'term2'
'month'=6,7 the elements = 'term3'
は私がこのような結果を得ることができますどのように
month term
0 1 term1
1 2 term1
2 3 term1
3 4 term2
4 5 term2
5 6 term3
6 7 term3
以下の結果を取得したいと思い
df=pd.DataFrame({'month':np.arange(1,8)})
だから、私は「月」列
を使用して列を追加したいと思いますか? 多分私達は簡単でシンプルな方法....
非常に簡単です!この列をdfに追加するにはどうすればよいですか? – Heisenberg
通常通り: 'df ['term'] = df.replace(条件)' – Boud
ありがとう!だから、月> 7 = term4とすると、どうすれば記述できますか? – Heisenberg