Skip to main content
code formatting
Source Link
tstenner
  • 10.4k
  • 10
  • 61
  • 94

I have a dataframe (df) in Python with a few features but I'm going to work with Age and Age_Mean columns.

In Age column, there are several null values. I would like to replace those null values with the same index from Age_Mean column.

Here is the code I used:

code
for i in df:
    if df['Age'].isnull().iloc[i] == True:
        df['Age'].iloc[i] == df['Age_Mean'].iloc[i]
    for i in df:
        if df['Age'].isnull().iloc[i] == True:
            df['Age'].iloc[i] == df['Age_Mean'].iloc[i]

This is my error message:

KeyError: 'the label [Age] is not in the [index]'

Please let me know what is wrong with this code.

I have a dataframe (df) in Python with a few features but I'm going to work with Age and Age_Mean columns.

In Age column, there are several null values. I would like to replace those null values with the same index from Age_Mean column.

Here is the code I used:

code
for i in df:
    if df['Age'].isnull().iloc[i] == True:
        df['Age'].iloc[i] == df['Age_Mean'].iloc[i]

This is my error message:

KeyError: 'the label [Age] is not in the [index]'

Please let me know what is wrong with this code.

I have a dataframe (df) in Python with a few features but I'm going to work with Age and Age_Mean columns.

In Age column, there are several null values. I would like to replace those null values with the same index from Age_Mean column.

Here is the code I used:

    for i in df:
        if df['Age'].isnull().iloc[i] == True:
            df['Age'].iloc[i] == df['Age_Mean'].iloc[i]

This is my error message:

KeyError: 'the label [Age] is not in the [index]'

Please let me know what is wrong with this code.

grammar / formatting + adding error message to question
Source Link

I have a dataframe (df) in Python with a few features but I'm going to work with Age and Age_Mean columns.

In Age column, there are several null values. I would like to replace those null values with the same index from Age_Mean column.

Here is the code I used but I get:

code
for i in df:
    if df['Age'].isnull().iloc[i] == True:
        df['Age'].iloc[i] == df['Age_Mean'].iloc[i]

This is my error message:

for i in df:
    if df['Age'].isnull().iloc[i] == True:
        df['Age'].iloc[i] == df['Age_Mean'].iloc[i]

KeyError: 'the label [Age] is not in the [index]'

Please let me know what is wrong with this code.

I have a dataframe (df) in Python with a few features but I'm going to work with Age and Age_Mean columns.

In Age column, there are several null values. I would like to replace those null values with the same index from Age_Mean column.

Here is the code I used but I get error:

for i in df:
    if df['Age'].isnull().iloc[i] == True:
        df['Age'].iloc[i] == df['Age_Mean'].iloc[i]

Please let me know what is wrong with this code.

I have a dataframe (df) in Python with a few features but I'm going to work with Age and Age_Mean columns.

In Age column, there are several null values. I would like to replace those null values with the same index from Age_Mean column.

Here is the code I used:

code
for i in df:
    if df['Age'].isnull().iloc[i] == True:
        df['Age'].iloc[i] == df['Age_Mean'].iloc[i]

This is my error message:

KeyError: 'the label [Age] is not in the [index]'

Please let me know what is wrong with this code.

Source Link
Sadegh
  • 47
  • 1
  • 1
  • 9
Loading