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
-1
votes
1 answer

pandas.DataFrame.fillna() inplace parameter "doesn't work"

Given a pandas.DataFrame named hospitals that looks like this: hospital gender age height ... mri xray children months 0 general m 33.0 1.640 ... NaN NaN NaN NaN 1 general m 48.0 1.930 ... NaN NaN …
ksnortum
  • 2,809
  • 4
  • 27
  • 36
-1
votes
1 answer

how can i use fillna(inplace=True) in for loop?

df = pd.read_csv('IMDB-Movie-Data.csv') dp = df.groupby('Director')['Revenue (Millions)'].mean() for i in dp.index: df.loc[df['Director']==i,'Revenue (Millions)'].fillna(dp[i],inplace = True) sorry for bad English dp is Revenue column's mean…
HLEE
  • 1
  • 1
-1
votes
1 answer

fill Nas with other column in pandas

I have some NAs and would like to fill them with values in another column in the same row. df = pd.DataFrame({"column A": ["Atlanta", "Atlanta", "New York", "",""], "column B": ["AT", "AT", "NY", "1",…
Daven1
  • 135
  • 8
-1
votes
1 answer

why is df.fillna() only filling some rows and the first column

Trying to fill all empty spots rows and columns with [], however fillna() will only do some rows and the first column. My code has worked in previous runs so I'm not sure what happened. df = df.fillna(value = "[]") print(df[['keywords']]) …
-1
votes
1 answer

Dataframe fill NaN average values using conditions

New to Pandas, I downloaded some public COVID data and I am now trying to fill NaN values. My dataframe looks like that: Now I am trying to fill the NaN values in the new_cases column. At first I added the mean of the column to those values using…
Hepodiu
  • 13
  • 1
-1
votes
1 answer

Pass a function to fillna()

I have a dataset with data from 2015 and 2016 for different buildings, their location information. Like this: As we can see, for the same OSEBuildingID most of their information are available and are the same, however, there are NaN in some…
Shyan
  • 7
  • 2
-1
votes
1 answer

Pandas merge rows if blank

I am looking to combine rows based on an id as long as the merge is not overwriting a value. so for a df : Column1 Column2 Column3 Column4 aa_1 123 456 aa_2 123 aa_4 123 aa_6 aa_1 789 …
Ksh
  • 85
  • 4
-1
votes
1 answer

Failed attempt to store values imputed from a function

Help guys, I'm trying to Impute missing values using a function, the function itself works in this respect, but fails to store the imputed values. The following shows the function, gh_Df is the dataset; val is the value in FacilityName variable and…
-1
votes
2 answers

Create a new column based off values in two others

I'm trying to merge two columns. Merging is not working out and I've been reading and asking questions for two days trying to find a solution so I'm going to go a different route. Since I have to change the column name after I merge anyway why not…
-1
votes
1 answer

KeyError: (nan, 'occurred at index 95')

I am working on Dataset and it has some missing values. I am trying to fill those values. Here a snap of my code. table = df.pivot_table(values='LoanAmount', index='Self_Employed' ,columns='Education', aggfunc=np.median) def fage(x): return…
majid bhatti
  • 83
  • 12
-1
votes
1 answer

How to fillna() all columns of a dataframe from a single row of another dataframe with identical structure

I have a train_df and a test_df, which come from the same original dataframe, but were split up in some proportion to form the training and test datasets, respectively. Both train and test dataframes have identical structure: A PeriodIndex with…
Cod.ie
  • 380
  • 5
  • 14
-1
votes
1 answer

Why is panda's fillna method not functioning?

I am working on this dataset and in one of the columns (LotFrontage) has 259 Nan values out of 1460. So when I use X.describe() it shows 259 nulls. I tried to fill those null values with 0's.. using isnull(). Once I view the result all the Nan…
Darren76
  • 11
  • 2
-1
votes
1 answer

While trying to fill the null values in my dataframe df 's "item_weight" column accord. to "Item_Identifier " .error is coming

avg_weight = df.pivot_table(index = "Item_Identifier",values = "Item_Weight") df_bool =df[df["Item_Weight"].isnull()] df.loc[df_bool,'Item_Weight'] = df.loc[df_bool,'Item_Identifier'].apply(lambda x: avg_weight[x])
-2
votes
1 answer

How do I use python reduce function to fill NaN values

I have a dataframe with missing data in several columns. In some of these columns, say 'Col_A' to 'Col_D', I'd like to replace them with 0. I tried it this way: reduce(lambda x : df.fillna({x : 0}, inplace=True), ['Col_A', 'Col_B', 'Col_C',…
JBVasc
  • 63
  • 8
-2
votes
1 answer

fillna on DataFrame with a simple function

I am looking for a way of filling NAs values of a DatFrame with a simple function : [row-1].value +1. The particularity of the dataframe is that it has multiple NAs one after another. Here is an example a the kind of DataFrame I am dealing with…
Madininais
  • 100
  • 9
1 2 3
35
36