根据小组填写南

时间:2017-05-24 19:00:36

标签: python pandas numpy dataframe

我想根据列值的意思填写NaN。 例如:

       Groups      Temp

1        5          27
2        5          23
3        5          NaN  (will be replaced by 25)
4        1          NaN  (will be replaced by the mean of the Temps that are in group 1)

有什么建议吗?谢谢!

1 个答案:

答案 0 :(得分:2)

fillnamean和lamdba功能与df = df.assign(Temp=df.groupby('Groups')['Temp'].transform(lambda x: x.fillna(x.mean()))) print(df) Temp 0 27.0 1 23.0 2 25.0 3 NaN 一起使用:

      [{
            "id": 1,
            "name": "Primary",
            "sal": [{
                    "id": "1",
                    "sal": "10"
                }, {
                    "id": "2",
                    "sal": "20"
                }]
            },{
            "id": 2,
            "name": "Secondary",
            "sal": [{
                    "id": "1",
                    "sal": "100"
                }, {
                    "id": "2",
                    "sal": "200"
                }
            ]
        }];


  UserService.hasUserValue(id, income).then(function(qualifiesforlowIncome){
     var isLowIncome = qualifiesforlowIncome
   }

输出:

public class JoinString {

public static void main( String[] args ) {

    String s1 = "13579";
    String s2 = "2468";
    final char[] str1 = s1.toCharArray();
    final char[] str2 = s2.toCharArray();
    int i;
    for ( i = 0; i < str1.length && i < str2.length; i++ ) {
        System.out.print( str1[i] + "" + str2[i] );
    }

    while ( i < str1.length ) {
        System.out.print( str1[i] + "" );
        i++;
    }

    while ( i < str2.length ) {
        System.out.print( str2[i] + "" );
        i++;
    }
}