fillna

Filling DF's NaN/Missing data from another DF

Filling DF's NaN/Missing data from another DF Question: I have two data frames: df1 = pd.DataFrame({‘Group’: [‘xx’, ‘yy’, ‘zz’, ‘x’, ‘x’, ‘x’,’z’,’y’,’y’,’y’,’y’], ‘Name’: [‘A’, ‘B’, ‘C’, None, None, None, None, None, None, None, None], ‘Value’: [5, 3, 4, 7, 1, 3, 6, 5, 9, 5, 4]}) df2 = pd.DataFrame({‘Name’: [‘A’, ‘A’, ‘B’, ‘B’], ‘Group’: [‘x’, …

Total answers: 1

Python Pandas ffill or bffill with multiple condition

Python Pandas ffill or bffill with multiple condition Question: I have a dataset like below : condition=[None,None,None,’condtion1′,None,None,None,’conditon2′,None,None,None] add_val = [None,None,None,10,None,None,None,20,None,None,None] df=pd.DataFrame({‘event_condition’:condition,’add_col’:add_val}) I want to fillna of add_col in terms of condition. When I meet condition 1 of event_condition, I want to ffill with value of 10 in a separate column called ‘on_condition1’. It should not …

Total answers: 1

pandas, how only fillna for last row with preceding line closest non-nan value

pandas, how only fillna for last row with preceding line closest non-nan value Question: import pandas as pd import numpy as np df = pd.DataFrame(np.random.randint(0, 10, (10, 10)), columns=list(‘ABCDEFGHIJ’)) df[df > 5] = np.nan for i in range(10): df.iloc[i, i % 10] = np.nan print(df) origin df is: A B C D E F G …

Total answers: 2

Trying to Sort by Values with NaN

Trying to Sort by Values with NaN Question: 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 …

Total answers: 1

How can I replace a nan value in an "object" column?

How can I replace a nan value in an "object" column? Question: How can I replace a nan value in a column which is an ‘object’, contains other str and ensure it goes into the main df and not just the slice. I have tried this covid_19_df.Country_code.fillna(‘OT’) but it is still empty D Country_code Country …

Total answers: 1

Filling null values based on the proportion of the categories in that column

Filling null values based on the proportion of the categories in that column Question: I have the following data col=[‘black’,’black’,’black’,’grey’,’white’,’grey’,’grey’,’nan’,’grey’,’black’,’black’,’red’,’nan’,’nan’,’nan’,’nan’,’black’,’black’,’white’] dd=pd.DataFrame({‘color’:col}) dd.replace(‘nan’,np.NaN,inplace=True) dd.sample(5) Out[1]: color 8 grey 14 NaN 7 NaN 2 black 9 black The following is the proportion of each color in the column dd.color.value_counts(normalize=True) Out[2]: black 0.500000 grey 0.285714 white 0.142857 red …

Total answers: 2

How to backfill values based on a category pandas

How to backfill values based on a category pandas Question: I have a table such as the following, with vaccine manufacturer, date and total_vaccinations as a cumulative sum of the vaccine manufacturer over time I am trying to ‘backfill’ the nulls, basically such that since this is a cumulative sum, dates with null values would …

Total answers: 1