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
0 answers

pandas' fillna not working on resampled pivot table

I am working on jupyter lab with pandas, version 0.20.1. I have a pivot table with a DatetimeIndex such as In [1]: pivot = df.pivot_table(index='Date', columns=['State'], values='B', fill_value=0, aggfunc='count') pivot Out…
0
votes
1 answer

How to fill in an incrementing integer in Pandas

Given a pd.DataFrame such as: print(pd.DataFrame([['a', 0, 'b'], ['c', 1, 'd'], ['f', 4, 'e']])) 0 1 2 0 a 0 b 1 c 1 d 2 f 4 e I would like to "fill in" rows by incrementing on the integer column. That is, I would like to obtain: …
splinter
  • 3,727
  • 8
  • 37
  • 82
0
votes
1 answer

Filling in blanks based off of criteria of another

So what I am trying to achieve is basically fill in blank rows in a column based off of another columns. so here is a snippet of what my dataframe looks like. Person_Name State_Abbrev Bool george, John CT NO george,…
Cannon
  • 309
  • 4
  • 19
0
votes
1 answer

python - fillna on conditional of multiple columns from 2 dataframes

I have 2 dataframes and I want to fill the na in df1 below, with the data that's in df2 but were the team column matches either the h or v column in df2: So in other words fillna for df1['temp', 'wspd', 'cond'] with those vales in df2 where…
chitown88
  • 27,527
  • 4
  • 30
  • 59
0
votes
1 answer

What's wrong with fillna in Pandas running twice?

I'm new to Pandas and Numpy. I was trying to solve the Kaggle | Titanic Dataset. Now I have to fix the two columns, "Age" and "Embarked" because they contains NAN. Now I tried the fillna without any success, soon to discover that I was missing the…
lu5er
  • 3,229
  • 2
  • 29
  • 50
0
votes
1 answer

How to find NaN conditionally in Pandas

I am doing the basic Data Exploration with 2 fields Outlet Type : array(['Supermarket Type1', 'Grocery Store', 'Supermarket Type3', 'Supermarket Type2'], dtype=object) Outlet_Size : array(['Medium', nan, 'Small', 'High'], dtype=object) I…
-1
votes
2 answers

In a pandas dataframe, how can I fill in missing values with a list of values

I have a dataframe that looks like this: df = pd.DataFrame({'animals': [None, 'cat', 'dog', None, 'hippo', 'elephant']}) The column animals has two None values. I want to replace the first missing value with one value and the second missing value…
-1
votes
1 answer

Data about Murder with missing values

I have a data set about femicides in Brazil. The columns are state, type_of_crime, year, quantity deaths_100K_pop. There are some missing values in quantity and I want to fill these with the mean of the columns quantity but I should do that…
-1
votes
1 answer

Convert a lambda function to a regular function

I'm trying to understand how can I convert a lambda function to a normal one. I have this lambda function that it supposed to fill the null values of each column with the mode def fill_nn(data): df= data.apply(lambda column:…
Dani
  • 3
  • 2
-1
votes
1 answer

Suggestions to replace nans with a mixture of previous and subsequent values

Assume I have a 1D array and want to replace / interpolate NaN blocks of length n with copies of the n/2 non-nan previous values and the n/2 non-nan subsequent values. Example 1: input = [1, 2, NaN, NaN, NaN, NaN, 3, 2] output= [1, 2, 1, 2, 3,…
dohe
  • 11
  • 1
-1
votes
1 answer

Pandas: Getting error when fillna in specific columns (ValueError: Columns must be same length as key)

I was trying to fill na values in categoric columns with some string. But error happened. I search everywhere for the solution, but found nothing. please help me # specify columns with legit na values legit_na_values_columns = ["MasVnrArea",…
-1
votes
1 answer

How to fill nan value in pandas dataframe from value in another column and above row?

I have df as follows: df = pd.DataFrame({"A":[0,np.nan,0,0,np.nan,1,np.nan,1,0,np.nan], "B":[0,1,0,0,1,1,1,0,0,0]}) Now, I need to replace nan values in column A with values from column B and one above row. for example: 2nd row…
szaki
  • 3
  • 1
-1
votes
2 answers

Fillna() inside a function

I'm trying to change a function that earlier filled missing years as timestamps (the data-type is int now), to one that would treat the missing years as int , and replace them by fillna(). def nons(row): for i in…
-1
votes
2 answers

Pandas: Fillna in the column with the value of the same group

I need to fill null values in the column with not null value of the same group. Example Desired Outcome I tried using transform with mode, but it didn't do the job. test['col2']=test['col2'].transform(lambda x:x.fillna(x.mode())
Amistreem
  • 1
  • 1
-1
votes
1 answer

Python automation, filling in one dataframe based on another dataframe

I am writing an automation script for work and the key feature of it is hanging me up. I need to fill in one spreadsheet based on information from another spreadsheet. I've created a simplified scenario that replicates my problem. One sheet, my…
T.J. King
  • 1
  • 1