mardi 7 avril 2020

How to implement if-else statement for every cell in transposed dataframe using Python

I'm new to Python
I have no idea how to incorporate if-else statement for every data after transposing .csv raw file using Pandas.

My transposed data using Pandas:

Voltage 0.2V 0.4V 0.6V 0.8V 1V 1.2V
Point A 0 15 100 5000 300 50
Point B 10000 4000 500 10 0 0
Point C 0 10 40 200 400 1000

Intended conditional statement inside every data of Point A, B & C

    If (data = 0){
    State = 0;
    }
    elsif (data >0 and data <= 10){
    State = 1;
    }
    elsif (data >10 and data <= 100){
    State = 2;
    }
    elsif (data >100 and data <= 1000){
    State = 3;
    }
    elsif (data >1000 and data <= 10000){
    State = 4;
    }
    else {
    State = "Invalid";
    }

My Expected output:

Voltage 0.2V 0.4V 0.6V 0.8V 1V 1.2V
Point A 0 2 2 4 3 2
Point B 4 4 3 1 0 0
Point C 0 1 2 3 3 3

Aucun commentaire:

Enregistrer un commentaire