假设我在这里有一个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
答案 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
或Series
与mul
的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