2

我有一堆翻斗式降雨数据记录为每分钟间隔的提示数。我已将其上传到 pandas 数据框,我需要能够将每个单独的列乘以 mm/tip 校准因子,但该列是 int 类型,而因子是 float 类型。我试过了:

df['Series'] = df['Series'].mul(constant) -> TypeError: unsupported operand type(s) for *: 'NoneType' and 'float'

df['Series'] *= constant -> TypeError: can't multiply sequence by non-int of type 'float'

df['Series'] = df['Series'].astype(float) * constant -> ValueError: could not convert string to float:

必须有一个简单的方法来做到这一点......帮助?

编辑:

这是我的数据的样子:

在此处输入图像描述

以下是我的阅读方式:

    def loaddata(filepaths):
        t1 = time.clock()
        for i,filepath in enumerate(filepaths):
            xl = pd.ExcelFile(filepath)
            df = xl.parse(xl.sheet_names[0], header=0, index_col=2, skiprows=[0,2,3,4], parse_dates=True)
            df = df.dropna(axis=1, how='all') 
            df = df.drop(['Decimal Year Day', 'Decimal Year Day.1', 'RECORD'], axis=1)
            df.index = pd.DatetimeIndex(((df.index.asi8/(1e9*60)).round()*1e9*60).astype(np.int64)).values

    return df

files = ["London Water Balance.xlsx"]
Water = loaddata(files)

这是dtype

Water.dtypes

[L] Drainage NE             float64
[L] Drainage SE              object
[L] Embedded raingauge E     object
[L] External raingauge       object
dtype: object
4

1 回答 1

4

尝试:

df.convert_objects(convert_numeric=True)

将其强制为数字列并将非数字元素设置为nan.

于 2013-07-24T03:16:46.483 回答