2016-12-01 9 views
0

列の一つのキーとしてカラムを使用して「ステータス」私のデータフレームでdfUnderInterpretationは「不足している」、「OK」のような値を持っており、「」。パンダ - 辞書

別の変数statusInterpretationは辞書です: { 'OK': 'INFO'、 '新': 'WARN'、 '行方不明': 'ERROR'}

私は、新しい列を作成したいです'通訳'は、私のデータフレームの「ステータス」のインデックスに基づくdict値を使用しています。 dfUnderInterpretation [ 'ステータスは']リストであるため、当然の下の

これは文句を言わない仕事します。

dfUnderInterpretation [ '解説'] = statusInterpretation.get(dfUnderInterpretation [ 'ステータス']、[なし)

答えて

1

あなたはapplyメソッドを使用することができます

dfUnderInterpretation['Status_Desc'] = dfUnderInterpretation['Status'].apply(lambda x: statusInterpretation.get(x)) 
関連する問題