user8967185 :
내가 언급 한 조건에 따라 다른 열 RevisedPrice를 추가 할
만약 가격 = 1,500 다음 RevisedPrice + = 가격 (단가 * 0.15) = 800 다른 가격 다음 RevisedPrice + = 가격 (단가 * 0.10) = 다른 RevisedPrice + 가격 (단가 * 0.5)의 경우
다음은 내 코드입니다 ------------
df['RevisedPrice']=[x+(0.15*x) if x==1500 else x+(0.10*x) if x==800 else x+(0.05*x) for x in df['Price']]
나는 나의 열 값을 얻고있다 RevisedPrice=Price+(Price*0.5)
하기 Shubham 샤르마 :
당신이 사용할 수있는 apply
팬더가 원하는 결과를 달성하기 위해 dataframe의 기능을. 여기에 당신이 시도 할 수있는 코드는 다음과 같습니다
def transform(row):
if row["Price"] == 1500:
scale = 0.15
elif row["Price"] == 800:
scale = 0.10
else:
scale = 0.5
return row["Price"] + row["Price"] * scale
df["RevisedPrice"] = df.apply(transform, axis=1)
그리고 당신은 실행할 때 >>>print(df.head())
산출:
Date Event Price RevisedPrice
0 11/8/2011 Music 1500 1725.0
1 11/9/2011 Poetry 800 880.0
2 11/10/2011 Music 1500 1725.0
3 11/11/2011 Comedy 1200 1800.0
4 11/12/2011 Poetry 800 880.0