download free.Q:
How to find maximum value of a column on condition that another column is not 0
I have a dataframe as:
import pandas as pd
from collections import defaultdict
df = pd.DataFrame([{'name':'abc','id':1},{'name':'pqr','id':0},{'name':'pqr','id':0}])
Out[1]:
name id
0 abc 1
1 pqr 0
2 pqr 0
I have to find the maximum id on the basis of name only if id is not 0. The output should be 1. How do I achieve this?
Expected output:
A:
In this case you can filter first, then use top_n and idxmax
df.query('id!=0').groupby('name').idxmax()
Out[418]:
0 1
Name: id, dtype: int64
Q:
Upload form and alert if uploaded image has been changed from previous version
I have an image uploader which works fine but I want to trigger a function to run if an image is updated.
My current code is
$(document).ready(function(){
$('#upload-image').change(function(){
var filename = $('#upload-image').val();
if(filename){
$.post("", {fileName: filename},
function(data){
alert("Your image has been uploaded");
}, "json");
}
});
});
I have a code snippet which is the original that I want to hook onto but it doesn't seem to be working.
jQuery('
Related links:
Comments