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

Pandas: Renaming "Unnamed: *" or "NaN" in data frame

Here's my code so far: import numpy as np import pandas as pd df = pd.read_excel(r'file.xlsx', index_col=0) Here's what it looks like: I want to rename the "Unnamed: *" columns to the last valid name. Here's what I've tried and the…
Mitch
  • 553
  • 1
  • 9
  • 24
0
votes
1 answer

Fill nan values with random value from another DataFrame pandas

I have a DataFrame with millon of rows and a lot of NaN values. Some example: index Company Area 0 Google Technology 1 Coca Cola Drinks 2 NaN Drinks 3 Apple Technology 4…
Raul Dip
  • 13
  • 4
0
votes
1 answer

Set all None and NaN values to 0 in a datframe - 'NoneType' object has no attribute 'isnull'

# Check for None and NaN values in the dataframe and clean if needed print("Any NaN values in the dataframe? True or False", end='\n') display(dfManual_With_NaN.isnull().values.any()) print("", end='\n') Output: True print("Total Number of…
Peter Lucas
  • 1,979
  • 1
  • 16
  • 27
0
votes
1 answer

Pandas fillna only on rows with at least 1 non-NaN value

Suppose I have a DataFrame constructed like this: import pandas as pd import numpy as np df = pd.DataFrame(data = {"col1":[3, np.nan, np.nan, 21], "col2":[4, np.nan, 12, np.nan], "col3":[33,…
Toby Petty
  • 4,431
  • 1
  • 17
  • 29
0
votes
1 answer

filling NAN and converting to int pandas

I have a dataframe of integers. Preview (starts from 3 due to first 3 rows removal): The original data in the 'pixel1' column is int, but the NAN there forced it to float. I tried to fix it with: X_train.fillna(method='ffill', inplace=True) X_train…
CIsForCookies
  • 12,097
  • 11
  • 59
  • 124
0
votes
3 answers

need to fill the NA values with the past three values before na values in python

need to fill the NA values with the past three values mean of that NA this is my dataset RECEIPT_MONTH_YEAR NET_SALES 0 2014-01-01 818817.20 1 2014-02-01 362377.20 2 2014-03-01 374644.60 3 2014-04-01 NA 4 2014-05-01…
0
votes
1 answer

Confusion with fillna() when None and NaN values in dataframe

When I apply fillna('New_Value) to the df below it fills all the None and NaN values except Column:D at Index 1. So what is the reason? Here is my code…
0
votes
1 answer

Filling null values with mean

I am given a data set with many NaN values and I wanted to fill the null value with the mean of each column. So I tried the following code: def fill_mean(): m = [df.columns.get_loc(c) for c in df.columns if c in missing] for i in m: …
plastico
  • 61
  • 1
  • 11
0
votes
1 answer

Fill missing values (na) with an list/series after modelling missing values

I am trying to plug the predicted missing values into original df (of course to the column with missing value). How could I do so? The predicted missing values are basically stored in a list/series whose length is the number of missing values in the…
Hieu Tran
  • 31
  • 4
0
votes
2 answers

Panda - Fillna - TypeError: cannot label index with a null key

I am trying to work with a Pandas DataFrame which has some NaN values. When I try to df.fillna(df.mean()) I get the following error and can not find a solution or reason for it: Error: TypeError: cannot label index with a null key All columns are…
D. Eggert
  • 1
  • 1
  • 5
0
votes
2 answers

pandas: fillna whole df with groupby

I have the following df with a lot more number columns. I now want to make a forward filling for all the columns in the dataframe but grouped by id. id date number number2 1 2001 4 11 1 2002 4 45 1 2003 NaN …
freddy888
  • 956
  • 3
  • 18
  • 39
0
votes
1 answer

pandas groupby not working as expected

I have a dataframe: >>> d6 Out[57]: Date sym Last M1 M2 dist code 52735 2017-11-23 C 0.10 4.72 -9.27 677.93 4250 - 12/15/2017 52736 2017-11-23 P 684.20 1.43 -106.09 …
dayum
  • 1,073
  • 15
  • 31
0
votes
1 answer

fillna function to replce NaN in a dataframe raising IOPub data rate exceeded

New to Python and working my way through a Panda import and cleanse. My code: df = pd.read_csv('SFIC_RFQs.csv', sep='~', usecols=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19, 20,21,22,23,24,25,26,27,28,29,30, 31,32]) df.isnull().sum().sum() …
Pete Lucas
  • 37
  • 1
  • 7
0
votes
1 answer

pandas valid null values

I am looking for the list of valid null values that pandas fillna() method will replace, e.g. 'NaN', 'NA', 'NULL', 'NaT'. I could not find it in the documentation.
James Steele
  • 645
  • 1
  • 6
  • 22
0
votes
2 answers

fillna does fill the dataframe in the NaN cells

What am I missing? fillna doesn't fill NaN values: #filling multi columns df with values.. df.fillna(method='ffill', inplace=True) df.fillna(method='bfill', inplace=True) #just for kicks df = df.fillna(method='ffill') df =…
Nir
  • 2,497
  • 9
  • 42
  • 71