Questions tagged [fillna]

Use this tag for pandas.DataFrame.fillna or pandas.Series.fillna

Fill missing values using the specified method for a DataFrame or a Series with pandas (see also interpolate, ffill, bfill)

Docs:

528 questions
0
votes
1 answer

Filling Null Values in Pandas

How to fill missing values based on conditions meeting from other columns such as I want to fill only mull values of Product Container Column based on the Product Category column if it is "Office supplies" in Product Category it will be a "Small…
0
votes
1 answer

Cannot fill in blank values in Pandas

I have a dataframe Gender 0 Female 1 Female 2 3 Female 4 Female with gender column which has some na values, and the split between genders is: Male 5453 Female 4543 Name: Gender, dtype: int64 When trying to fill in the missing…
Esther
  • 49
  • 2
  • 8
0
votes
2 answers

Fill in the missing data using Pandas

What's the best way to fill in the missing data using Pandas . I have a list of visitors where the exit time or the entry time is missing . visitor entry exit A 16/02/2016 08:46 16/02/2016 09:01 A 16/02/2016 09:20 16/02/2016…
Wha
  • 23
  • 4
0
votes
0 answers

Inner working of fillna() when used with groupby and transform

I am trying to learn ML by solving the Titanic ML problem at kaggle and there are many Age values that are missing. I am following a tutorial to solve the problem. if I use median_age = df.groupby('Title')['Age'].transform('median') then it gives…
Deshwal
  • 3,436
  • 4
  • 35
  • 94
0
votes
1 answer

R Function that replaces NAs with lagged values

I am trying to write a function that replaces the missing values of selected variables in a data frame with their lagged values (I am using a one obs. lag) in R. I have successfully written the following for loop to do this: testdata <-…
benalbert342
  • 71
  • 1
  • 4
0
votes
1 answer

Fill multiple rows in between pandas dataframe rows on condition

I have a dataset like below: pd.DataFrame({'Date':['2019-01-01','2019-01-03','2019-01-01','2019-01-04','2019-01-01','2019-01-03'],'Name':['A','A','B','B','C','C'],'Open Price':[100,200,300,400,500,600],'Close Price':[200,300,400,500,600,700]}) Now…
0
votes
1 answer

Why can't I create a dataframe with fillna python function?

I have a dataframe which I'm trying to replace all NaN's with the word "Unknown". I tried using the following code: reviews[reviews.country.fillna("Unknown")] This does not work. What will work, is the code below which to my knowledge creates a…
mikelowry
  • 1,307
  • 4
  • 21
  • 43
0
votes
1 answer

Need to add a row based off criteria from another column

I need to add a row in my df with certain text based off criteria from another column. Depending on the column criteria, then a row will be added under that certain row. ID Name Order Children Pet 12 Joe Parent yes …
DeAnna
  • 404
  • 6
  • 17
0
votes
1 answer

How to fillna() with mean of left- and right- column neighbor cells, row by row?

I'd like to replace nans in a dataframe with: If nan is in between two columns with values, with the mean of both columns ('prev' and 'next') Else, keep the same path of the series. For instance: In[1]: df = pd.DataFrame([[1, 2,np.nan,np.nan],…
Rose
  • 203
  • 2
  • 10
0
votes
0 answers

Grouping columns in a pandas dataframe according to resampled datetime index and then filling NAs of every group with its group median

I have a time series(df1) of passenger boarding count data with a DateTimeindex like below: P_Boarded Timestamp 2019-06-12 05:01:12 2.0 2019-06-12 05:30:22 NaN 2019-06-12 06:02:10 6.0 2019-06-12 06:32:54 5.0 2019-06-12…
Prachi
  • 494
  • 3
  • 8
  • 21
0
votes
2 answers

How to pd.fillna(mean()) acccording to a column value which changes?

I have the following dataframe: data/hora 2017-08-18 09:22:33 22162 NaN 65.9 NaN NaN 2017-10-03 11:08:26 22162 NaN 60.5 …
0
votes
1 answer

Pandas fillna row wise?

It'a simple example. d=pd.DataFrame({'x':[1,None,None,3,4],'y':[3,2,3,None,7],'z':[None,None,None,None,None]}) d['t']=d.mean(axis=1) Out[96]: x y z t 0 1.0 3.0 None 2.0 1 NaN 2.0 None 2.0 2 NaN 3.0 None 3.0 3 3.0 NaN …
adafdwwf
  • 162
  • 3
  • 12
0
votes
1 answer

Iterrows not keeping the fillna

I want to fill in some NaN values from a DataFrame with a value which I can calculate from a linear regression equation. Since not all the values from the DataFrame are NaN, I decided to loop over it. This is the DataFrame: Country Afghanistan…
Daniel
  • 471
  • 3
  • 8
  • 18
0
votes
2 answers

Fill NaN's within 1 column of a df via lookup to another df via pandas

I seen various versions of this question but none of them seem to fit with what I am attempting to do: here's my data: Here's the df with the NaNs: df = pd.DataFrame({"A": ["10023", "10040", np.nan, "12345", np.nan, np.nan, "10033", np.nan,…
jmb277
  • 558
  • 4
  • 19
0
votes
1 answer

Dask DataFrame after Apply cannot reindex from a duplicate axis

I'am trying to change nan values of item_price to the mean value based on item_id in the following dask dataframe: all_data['item_price'] = all_data[['item_id','item_price']].groupby('item_id')['item_price'].apply(lambda x:…
mj1261829
  • 1,200
  • 3
  • 26
  • 53