условное деление в python pandas на несколько столбцов

Вот пример наивного кода, чтобы объяснить, что я предлагаю в своих комментариях (я уверен, что есть лучшие способы кодирования логики, но, надеюсь, он получает суть) ...

    static public byte[] AddBytes(byte[] a, byte[] b)
    {
        if (a.Length != b.Length)
        {
            throw new InvalidOperationException("Mismatched array lengths is not currently supported");
        }

        byte[] result = new byte[a.Length + 1];
        int carry = 0;

        for (int x = a.Length - 1; x >= 0; x--)
        {
            int tempresult = a[x] + b[x] + carry;
            result[x + 1] =(byte)(tempresult); 
            carry = tempresult / (byte.MaxValue + 1); 
        }

        if (carry > 0)
        {
            // Carried into extra byte, so return it
            result[0] = (byte)carry;
            return result;
        }
        // no carry into extra byte, so remove it
        return result.Skip(1).ToArray();
    }
    static void Main(string[] args)
    {
        byte[] a = { 1, 1, 1 };
        byte[] b = { 1, 1, 1 };
        byte[] c = { 1, 1, 255 };
        byte[] d = { 0, 0, 1 };
        byte[] e = { 255, 255, 255 };
        byte[] f = { 255, 255, 255 };

        var x = AddBytes(a, b);
        x = AddBytes(c, d);
        x = AddBytes(e, f);
    }

Как я уже сказал, это по существу предполагает, что массив байтов представляет числа ...

Итак, {1,1,1} эквивалентен 0x10101 или 65793 65793 + 65793 = 131586 или 0x20202, т.е. {2,2,2}

и, {1,1,255} + {0,0,1} эквивалентно 0x101FF + 0x1 или 66047 + 1 = 66048 или 0x10200, т.е. {1,2 , 0}

-3
задан Nihal 13 July 2018 в 06:09
поделиться