Pandas - fillna with row subset


Left__

I'm trying to fill certain rows with 0's where certain conditions apply. I'm trying now:

df.loc[:,(df.Available == True) & (df.Intensity.isnull())].Intensity = df.loc[(df.Available == True) & (df.Intensity.isnull())].Intensity.fillna(0, inplace=True)

This doesn't work IndexingError: Unalignable boolean Series key provided, but when I try

df.loc[(df.Available == True) & (df.Intensity.isnull())].Intensity = df.loc[(df.Available == True) & (df.Intensity.isnull())].Intensity.fillna(0, inplace=True)

Register as an updated copy. How can I do this? Thanks!

jelles

I don't think you even need to , even if fillnayou're already dealing with rows where the Intensity is null .

df.loc[(df.Available) & (df.Intensity.isnull()), 'Intensity'] = 0

or you can do

df.loc[df.Available, 'Intensity'] = df.loc[df.Available, 'Intensity'].fillna(0)

Related


Pandas - fillna with row subset

Left__ I'm trying to fill certain rows with 0's where certain conditions apply. I'm trying now: df.loc[:,(df.Available == True) & (df.Intensity.isnull())].Intensity = df.loc[(df.Available == True) & (df.Intensity.isnull())].Intensity.fillna(0, inplace=True) T

Pandas - fillna with row subset

Left__ I'm trying to fill certain rows with 0's where certain conditions apply. I'm trying now: df.loc[:,(df.Available == True) & (df.Intensity.isnull())].Intensity = df.loc[(df.Available == True) & (df.Intensity.isnull())].Intensity.fillna(0, inplace=True) T

Pandas - fillna with row subset

left__ I'm trying to fill certain rows with 0's where certain conditions apply. I'm trying now: df.loc[:,(df.Available == True) & (df.Intensity.isnull())].Intensity = df.loc[(df.Available == True) & (df.Intensity.isnull())].Intensity.fillna(0, inplace=True) T

Pandas - fillna with row subset

left__ I'm trying to fill certain rows with 0's where certain conditions apply. I'm trying now: df.loc[:,(df.Available == True) & (df.Intensity.isnull())].Intensity = df.loc[(df.Available == True) & (df.Intensity.isnull())].Intensity.fillna(0, inplace=True) T

Pandas - fillna with row subset

left__ I'm trying to fill certain rows with 0's where certain conditions apply. I'm trying now: df.loc[:,(df.Available == True) & (df.Intensity.isnull())].Intensity = df.loc[(df.Available == True) & (df.Intensity.isnull())].Intensity.fillna(0, inplace=True) T

Pandas fillna not working on subset of dataset

Hang Dabang I want to impute missing values df['box_office_revenue']with df['release_date'] == xand specified median df['genre'] == y. Here is my median finder function below. def find_median(df, year, genre, col_year, col_rev): median = df[(df[col_year] ==

Pandas fillna not working on subset of dataset

Hang Dabang I want to impute missing values df['box_office_revenue']with df['release_date'] == xand specified median df['genre'] == y. Here is my median finder function below. def find_median(df, year, genre, col_year, col_rev): median = df[(df[col_year] ==

Pandas fillna not working on subset of dataset

Hang Dabang I want to impute missing values df['box_office_revenue']with df['release_date'] == xand specified median df['genre'] == y. Here is my median finder function below. def find_median(df, year, genre, col_year, col_rev): median = df[(df[col_year] ==

Pandas fillna not working on subset of dataset

Hang Dabang I want to impute missing values df['box_office_revenue']with df['release_date'] == xand specified median df['genre'] == y. Here is my median finder function below. def find_median(df, year, genre, col_year, col_rev): median = df[(df[col_year] ==

Pandas fillna not working on subset of dataset

Hang Dabang I want to impute missing values df['box_office_revenue']with df['release_date'] == xand specified median df['genre'] == y. Here is my median finder function below. def find_median(df, year, genre, col_year, col_rev): median = df[(df[col_year] ==

Pandas fillna not working on subset of dataset

Hang Dabang I want to impute missing values df['box_office_revenue']with df['release_date'] == xand specified median df['genre'] == y. Here is my median finder function below. def find_median(df, year, genre, col_year, col_rev): median = df[(df[col_year] ==

Pandas fillna not working on subset of dataset

Hang Dabang I want to impute missing values df['box_office_revenue']with df['release_date'] == xand specified median df['genre'] == y. Here is my median finder function below. def find_median(df, year, genre, col_year, col_rev): median = df[(df[col_year] ==

Pandas fillna not working on subset of dataset

Hang Dabang I want to impute missing values df['box_office_revenue']with df['release_date'] == xand specified median df['genre'] == y. Here is my median finder function below. def find_median(df, year, genre, col_year, col_rev): median = df[(df[col_year] ==

Pandas | Fillna between specific indices (varies with row)

Pereira So I'm mostly having issues with performance, as I can actually output the expected results, but it's taking a long time. I'm looking for a better way to do the following to speed up the implementation. The problem is filling nulls in pandas DataFrame

Pandas | Fillna between specific indices (varies with row)

Pereira So I'm mostly having issues with performance, as I can actually output the expected results, but it takes a long time. I'm looking for a better way to do the following to speed up the implementation. The problem is filling nulls in pandas DataFrame row

Pandas | Fillna between specific indices (varies with row)

Pereira So I'm mostly having issues with performance, as I can actually output the expected results, but it's taking a long time. I'm looking for a better way to do the following to speed up the implementation. The problem is filling nulls in pandas DataFrame

Pandas | Fillna between specific indices (varies with row)

Pereira So I'm mostly having issues with performance, as I can actually output the expected results, but it's taking a long time. I'm looking for a better way to do the following to speed up the implementation. The problem is filling nulls in pandas DataFrame

Pandas delete row if it is a subset of another row

Chris I've searched a lot, but nothing seems to work. Suppose when dfsomething like: import pandas as pd import numpy as np df = pd.DataFrame([['a','b','c'], ['a',np.nan,'b'], [np.nan, 'b', 'a'], ['a', 'd', 'b']]) df 0 1 2 0 a b c 1 a NaN

Pandas delete row if it is a subset of another row

Chris I've searched a lot, but nothing seems to work. Suppose when dfsomething like: import pandas as pd import numpy as np df = pd.DataFrame([['a','b','c'], ['a',np.nan,'b'], [np.nan, 'b', 'a'], ['a', 'd', 'b']]) df 0 1 2 0 a b c 1 a NaN

Python Pandas Fillna only one row with specific value

Lagos edit: I have (not very simple) a dataframe: df = pd.DataFrame([1, 2, np.nan, np.nan, np.nan, np.nan, 3, 4 , np.nan, np.nan, np.nan, 5], columns=['att1']) att1 0 1.0000 1 2.0000 2 nan 3 nan 4 nan 5 nan 6 3.0000 7 4.0000 8

Pandas subset and put row based on column value

Ramesh my df: dframe = pd.DataFrame({"A":list("aaaabbbbccc"), "C":range(1,12)}, index=range(1,12)) Out[9]: A C 1 a 1 2 a 2 3 a 3 4 a 4 5 b 5 6 b 6 7 b 7 8 b 8 9 c 9 10 c 10 11 c 11 to a subset based on column v