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

How to add 1 to previous data if NaN in pandas

I was wondering if it is possible to add 1 (or n) to missing values in a pandas DataFrame / Series. For example: 1 10 nan 15 25 nan nan nan 30 Would return : 1 10 11 15 25 26 27 28 30 Thank you,
Youpi14
  • 21
0
votes
1 answer

How to fill values in pandas column (which was zero before) to a proper integer/float values from the next coming rows?

I have been working on large dataset with Lat & Longitude Data. I am doing interpolation for the whole df, so before that i just want my latitude and longitude column to have elements to filled with values without zeros. My Dataframe (explanation…
Mari
  • 698
  • 1
  • 8
  • 27
0
votes
1 answer

Python Pandas: Forward Fill with Arithmetic

I have the following DataFrame: AAPL shares GOOG shares MSFT shares date 2019-01-01 NaN 10.0 NaN 2019-01-05 NaN NaN 15.0 2019-01-12 …
Sterling Butters
  • 1,024
  • 3
  • 20
  • 41
0
votes
1 answer

Fuction can not interpret nan value

I am trying to get rid of NaN values in a dataframe. Instead of filling NaN with averages or doing ffill I wanted to fill missing values according to the destribution of values inside a column. In other words, if a column has 120 rows, 20 are NaN,…
0
votes
1 answer

Replace "NaN" value by last valid value for only one column in a dataframe with column multi-index (df.fillna)

I'm working with Python 3.6.5. Here is a little script to generate a multi index dataframe with some "NaN" value. import pandas as pd import numpy as np att_1 = ['X', 'Y'] att_2 = ['a', 'b'] df_1 = pd.DataFrame(np.random.randint(10,19,size=(5,…
David
  • 450
  • 3
  • 14
0
votes
1 answer

fillna pandas doesn't affect original dataframe

I'm trying to fill missing values for specific column but the original data frame doesn't change though I'm using inplace=True I tried this: all_data.loc[all_data['GarageType'] == 'Detchd', 'GarageCond'].fillna('TA', inplace=True) and…
user10667046
0
votes
1 answer

Pandas Dataframe row value equals value above + 1

I have a dataframe with the first week of each year. I'm trying to get a list of week numbers. So essentially I need to fill na's with the number above (1) + 1. Here's my code so far FirstDay= {'Date': { 'Wk117' :'01-07-2016' …
fred.schwartz
  • 2,023
  • 4
  • 26
  • 53
0
votes
1 answer

PySpark: fillna function not working even after casting type

I have a dataframe with two columns which looks like the following: +----+-----+ |type|class| +----+-----+ | | 0| | | 0| | | 0| | | 0| | | 0| +----+-----+ only showing top 5 rows I'm trying to fill in empty values with…
ahajib
  • 12,838
  • 29
  • 79
  • 120
0
votes
2 answers

dataframe combine_first does not work as well as fillna

the first dataframe is: data_date cookie_type dau next_dau dau_7 dau_15 0 20181006 avg(0-d) 2288 NaN NaN NaN 1 20181006 avg(e-f) 2284 NaN NaN NaN 2 20181007 avg(e-f) 2296 100 NaN …
Archer
  • 335
  • 3
  • 12
0
votes
1 answer

How to replace NaNs by first value of the year in pandas DataFrame?

I have a dataframe like the following, where I have for certain names (A and C) a value the first month of the year . df date name value 0 201601 A 3 1 201607 A NaN 2 201612 A NaN 3 201601 B …
emax
  • 6,965
  • 19
  • 74
  • 141
0
votes
1 answer

how replace value the forward minus -1?

Is A.fillna(method='ffill') used to replace the succeeding value? How can we replace the succeeding value with minus -1 in each step?
Minou92
  • 137
  • 7
0
votes
0 answers

More efficient fillna(numpy)

I need an array version of a function similar to Pandas.fillna, in the forum I collected a lot of answers to create the following function, but it is still 3 times times slower than Pandas.fillna, I want to know if there is a better way to optimize,…
weidong
  • 159
  • 8
0
votes
1 answer

Pandas Dataframe fillna working inconsistenly even with replace inplace set to true

The program retrieves JSON data from RESTApi import requests import pandas as pd pd.set_option('display.max_columns', None) pd.set_option('display.max_rows',1000) url =…
Dvusrgme
  • 369
  • 1
  • 5
  • 13
0
votes
1 answer

filevalues.fillna not filling for some files only

readfile = pd.read_csv('42.csv') filevalues= readfile.loc[readfile['Customer'].str.contains('Lam Dep', na=False), 'Jun-18\nQty'] filevalues = filevalues.fillna(0) print(filevalues) I have sales forecast files that have the same format as each…
Michael Norman
  • 547
  • 3
  • 9
  • 20
0
votes
2 answers

Pandas - Handle NaN in Pivot Table with Categorical

I'm creating multiple pivot tables using a Categorical dtype then merging them into one big pivot table / dataframe. However, in some cases I get NaN when I perform the merge, and when I try to fillna(0), I get the following error: ValueError: fill…
Walt Reed
  • 1,336
  • 2
  • 17
  • 26