Trying to Sort by Values with NaN

I have a dataset that I need to change the NaNs with a value when I do so there is no value stored. the data looks like this: id type status job_id 1 EMP Pending 1 EMP Pending 101 1 Contract Aproved 391 2 EMP Approved 521 2 Contract Approved This is the code I… Read More Trying to Sort by Values with NaN

Imputation: Why do we replace the nan value with the Mean, and doesn't it affect our data?

Why do we replace the nan value in DataFrame with the Mean, and when we change it doesn’t it affect our data ? 0 1.048242 1 1.688173 2 NaN 3 0.194162 4 0.194162 5 0.493194 6 NaN 7 0.675041 8 NaN 9 0.101743 10 3.112086 df[‘view_duration’].fillna(mean,inplace = True) 0 1.048242 1 1.688173 2 0.938350 3… Read More Imputation: Why do we replace the nan value with the Mean, and doesn't it affect our data?

Pandas resample based on string like PeriodIndex

I have a dataframe like as below df = pd.DataFrame({‘subject_id’:[1,1,1,1,1,2,2,2,2,2], ‘qtr_info’ :[‘2017Q1′,’2017Q3′,’2017Q4′,’2018Q1′,’2018Q4′,’2017Q1′,’2017Q4′,’2018Q2′,’2018Q4′,’2019Q1’], ‘val’ :[5,5,5,5,1,6,5,5,8,3], ‘Prod_id’:[‘A’,’B’,’C’,’A’,’E’,’Q’,’G’,’F’,’G’,’H’]}) I would like to do the below a) Fill all the missing quarters of a subject b) fillna for other columns using the mean value for respective columns (for the same subject). Don’t refer other subject ids for computing mean… Read More Pandas resample based on string like PeriodIndex

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

How to check values from list in DataFrame column and insert value by condition?

for example, I have the next list: l = [‘a’, ‘x’, ‘t’] and the DataFrame: a = [{‘sufix’: ‘a’, ‘qty’: 5}, {‘sufix’: ‘b’, ‘qty’: 2}, {‘sufix’: ‘c’, ‘qty’: 7}, {‘sufix’: ‘x’, ‘qty’: 9}, {‘sufix’: ‘t’, ‘qty’: 4}, {‘sufix’: ‘p’, ‘qty’: 1}] df = pd.DataFrame(a) print(df) What I need, if values from list -> l are… Read More How to check values from list in DataFrame column and insert value by condition?