How to determine whether the other then() methods can be omitted?

The following codes illustrate a form which allows optionally pasting the value from the clipboard before automatically submitting. It uses two then() methods. Please use Chrome to test it because Firefox does not support it yet. const input = document.querySelector(‘input’), submitButton = document.querySelector(‘button[type=”submit”]’), pasteAndSubmitButton = document.querySelector(‘button[type=”button”]’); pasteAndSubmitButton.addEventListener(‘click’, function () { navigator.clipboard.readText() .then(clipText => input.value =… Read More How to determine whether the other then() methods can be omitted?

pandas multIndex from product – ignore same row comparison

I have a pandas dataframe like as shown below Company,year T123 Inc Ltd,1990 T124 PVT ltd,1991 ABC Limited,1992 ABCDE Ltd,1994 tf = pd.read_clipboard(sep=’,’) tf[‘Company_copy’] = tf[‘Company’] I would like to compare each value from tf[‘company’] against each value of tf[‘company_copy] but exclude same matching row number or index number, string For ex: I want T123… Read More pandas multIndex from product – ignore same row comparison

Dynamic top 3 and percentage total using pandas groupby

I have a dataframe like as shown below id,Name,country,amount,qty 1,ABC,USA,123,4500 1,ABC,USA,156,3210 1,BCE,USA,687,2137 1,DEF,UK,456,1236 1,ABC,nan,216,324 1,DEF,nan,12678,11241 1,nan,nan,637,213 1,BCE,nan,213,543 1,XYZ,KOREA,432,321 1,XYZ,AUS,231,321 sf = pd.read_clipboard(sep=’,’) I would like to do the below a) Get top 3 based on amount for each id and other selected columns such as Name and country. Meaning, we get top 3 based id… Read More Dynamic top 3 and percentage total using pandas groupby

Pandas groupby and compute ratio of values with NA in multiple columns

I have a dataframe like as below id,status,amount,qty 1,pass,123,4500 1,pass,156,3210 1,fail,687,2137 1,fail,456,1236 2,pass,216,324 2,pass,678,241 2,nan,637,213 2,pass,213,543 df = pd.read_clipboard(sep=’,’) I would like to do the below a) Groupby id and compute the pass percentage for each id b) Groupby id and compute the average amount for each id So, I tried the below df[‘amt_avg’] =… Read More Pandas groupby and compute ratio of values with NA in multiple columns

pandas replace dataframe float values using int keys of nested dict

I have a dataframe and dictionary like as shown below ID,Name,value,total, 1,Ajay,2.00,35 1,Dan,3.00,65 2,Ajay,2,78 2,Rajini,0.0,98 3,Ajay,3.00,53 3,Rad,75.25,21 df1 = pd.read_clipboard(sep=’,’) output = {‘Ajay’: {1: ‘ABC’, 2: ‘DEF’, 3: ‘DUMMA’, 4: ‘CHUMMA’}, ‘Dan’: {0: ‘KOREA’, 1: ‘AUS/NZ’, 2: ‘INDIA’, 3: ‘ASEAN’}} I would like to do the below a) Replace the values in value column by… Read More pandas replace dataframe float values using int keys of nested dict

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