大熊猫,行智点产品

时间:2017-12-13 06:37:05

标签: python pandas

假设我在这里有一个DataFrame

        $.ajax({
              url: '../...',
              type: 'POST',
              dataType: 'JSON',                         
              success: function(data){
                      if (data.length) {

                     // complex and unreadable code
                    // cannot be posted here.

                      $.ajax({
                      url: '../library/index.php?action=librarydetailssearch',
                      type: 'POST',
                      dataType: 'JSON',
                      data: {studentid:studentid},
                                            asyn: false,
                                            success: function(data){
                                            if (data.length) {
                                         }
                                     }
                         });

                       }
                    });

如何逐行乘以向量In [2]: df = pd.DataFrame({'COL1':[1,2,3,4,5,9], 'COL2':[5,3,6,9,2,4]}) In [3]: df Out[3]: COL1 COL2 0 1 5 1 2 3 2 3 6 3 4 9 4 5 2 5 9 4 ,以便[2, 1]

df

1 个答案:

答案 0 :(得分:2)

您可以numpy array

多个
print (df * np.array([2,1]))
   COL1  COL2
0     2     5
1     4     3
2     6     6
3     8     9
4    10     2
5    18     4

Seriesmul的df列相同的索引:

print (df.mul(pd.Series([2,1], index=df.columns), axis=1))
   COL1  COL2
0     2     5
1     4     3
2     6     6
3     8     9
4    10     2
5    18     4