Python Pandas convert column data type

后端 未结 2 2004
盖世英雄少女心
盖世英雄少女心 2021-01-24 02:48

I know a question like this has been asked zillion types, but so far I have not been able to find an answer to this question.

I have joined two .csv files together with

2条回答
  •  感动是毒
    2021-01-24 03:44

    (Your code is missing a parenthesis at the end of nscap(df_joined["NS"].)

    As @EdChum and @TheLaughingMan write, clip_upper is what you want here. This answer just addresses the direct reason for the error you're getting.

    In the function

    def nscap(ns):
        if ns <= 13:
            x = ns
        elif ns > 13:
            x = 13
        return x
    

    effectively, ns <= 13 operations on a numpy.ndarray. When you compare such an array to a scalar, broadcasting takes place, and the result is an array where each element indicates whether it was true for it or not.

    So

    if ns <= 13:
    

    translates to something like

    if numpy.array([True, False, True, True]):
    

    and it's impossible to understand whether this is true or not. That's the error you're getting: you need to specify whether you mean if all entries are true, if some entry is true, and so on.

提交回复
热议问题