Find percent difference between two columns, that share same root name, but differ in suffix

My question is somewhat similar to subtracting-two-columns-named-in-certain-pattern I’m having trouble performing operations on columns that share the same root substring, without a loop. Basically I want to calculate a percentage change using columns that end with ‘_PY’ with another column that shares the same name except for the suffix. What’s a possible one line solution,… Read More Find percent difference between two columns, that share same root name, but differ in suffix

C# – Can't get this seemingly simple web request working

I have the following powershell Web-Request that works correctly for sending a command to a PTZ camera: Invoke-WebRequest -UseBasicParsing -Uri "http://192.168.111.75/ajaxcom" ` -Method "POST" ` -Headers @{ "Accept"="application/json, text/javascript, */*; q=0.01" "Accept-Encoding"="gzip, deflate" "Accept-Language"="en-US,en;q=0.9" "DNT"="1" "Origin"="http://192.168.111.75" "X-Requested-With"="XMLHttpRequest" } ` -ContentType "application/x-www-form-urlencoded; charset=UTF-8" ` -Body "szCmd=encodedStringHere" I’m trying to recreate this in C# but I can’t… Read More C# – Can't get this seemingly simple web request working

How to efficiently updating list of dict key-values with list of value in Python

The objective is to update new key-value in a list of dict, whereby the value is from another nested list. This can be realised via ls1=[[1,23],[2,34,5]] ls2=[dict(t=1),dict(t=1)] all_data=[] for x,y in zip(ls1,ls2): y[‘new’]=x all_data.append(y) For compactness, I would like to have the for-loop in the form of list comprehension. all_data=[y.update({‘new’:x}) for x,y in zip(ls1,ls2)] But,… Read More How to efficiently updating list of dict key-values with list of value in Python

Create dictionary from 3 lists – python

Looking for some help in creating a dictionary using 3 python lists a = [‘alpha’,’bravo’,’charlie’] b = [‘a’,’b’,’c’] c = [1,2,3] output: {‘alpha’: {‘letter’: ‘a’, ‘number’: 1}, ‘bravo’: {‘letter’: ‘b’, ‘number’: 2}, ‘charlie’: {‘letter’: ‘c’, ‘number’: 3}} I tried something like this. This may be close, but needs some tweaking: {k: dict(v) for k,v in… Read More Create dictionary from 3 lists – python

Pandas groupby and get nunique of multiple columns in a dataframe

I have a dataframe like as below stu_id,Mat_grade,sci_grade,eng_grade 1,A,C,A 1,A,C,A 1,B,C,A 1,C,C,A 2,D,B,B 2,D,C,B 2,D,D,C 2,D,A,C tf = pd.read_clipboard(sep=’,’) My objective is to a) Find out how many different unique grades that a student got under Mat_grade, sci_grade and eng_grade So, I tried the below tf[‘mat_cnt’] = tf.groupby([‘stu_id’])[‘Mat_grade’].nunique() tf[‘sci_cnt’] = tf.groupby([‘stu_id’])[‘sci_grade’].nunique() tf[‘eng_cnt’] = tf.groupby([‘stu_id’])[‘eng_grade’].nunique() But… Read More Pandas groupby and get nunique of multiple columns in a dataframe

extract path name based on a string

Below is my worked examples: from itertools import zip_longest test2 = [‘register/adam/users_photo3.jpg’, ‘register/adam/users_photo4.jpg’, ‘register/justin/users_photo1.jpg’, ‘register/justin/users_photo2.jpg’, ‘register/adam/users_photo3.jpg’, ‘register/adam/users_photo4.jpg’, ‘register/justin/users_photo1.jpg’, ‘register/justin/users_photo2.jpg’, ‘register/steve/users_photo1.jpg’, ‘register/steve/users_photo2.jpg’, ‘register/justin/users_photo1.jpg’, ‘register/justin/users_photo2.jpg’, ‘register/steve/users_photo1.jpg’, ‘register/steve/users_photo2.jpg’, ‘register/justin/users_photo1.jpg’, ‘register/justin/users_photo2.jpg’] test = ["justin","adam"] filter_list = [] for p,q in zip_longest(test,list_of_files): for r in list_of_files: if str(p) in r: filter_list.append(r) testmain=[p for p,r in zip_longest(test2,filter_list) if str(r) not in… Read More extract path name based on a string