代码之家  ›  专栏  ›  技术社区  ›  Shuvayan Das

如何用python中的nan替换空序列值

  •  0
  • Shuvayan Das  · 技术社区  · 7 年前

    metrics_dict['skewness'] = data_col.skew().values[0]
    metrics_dict['kurtosis'] = data_col.kurt().values[0]
    metrics_dict['mean'] = np.mean(data_col)[0]
    metrics_dict['median'] = np.median(data_col)
    

    IndexError: index out of bounds
    

    Index          device
    61021           C:2
    61022          D:3+
    61023          D:3+
    61024           B:1
    61025          D:3+
    61026           C:2 
    

    3 回复  |  直到 7 年前
        1
  •  1
  •   jpp    7 年前

    pd.DataFrame.select_dtypes 以下内容:

    numerics = ['int16', 'int32', 'int64', 'float16', 'float32', 'float64']
    
    numeric_cols = df.select_dtypes(include=numerics).columns
    
    for col in df:
        if col in numeric_cols:
            # calculate & add some values to dictionary
        else:
            # add NA values to dictionary
    
        2
  •  0
  •   Dovi    7 年前

    try:
       # whatever you do that might rise an IndexError
    except IndexError:
       # append NA to dict
    
        3
  •  -1
  •   chirag    7 年前

    df[df['col'] == ''] = np.nan
    

    希望这有帮助。