0

I have a column in my csv file that consists of 273 different values. I am trying to set conditionals so that I can label them high or low that way I can then plot them on a basemp. The picture I attached is what I am trying to create with my own data. If anyone has any advice or tips it would really help. I am a first-time coder, sorry if I didn't explain it thoroughly. I am using python in a google co-lab notebook similar to jupyter notebook.

Map I am trying to create that shows the high and low values through change of color

  • 1
    You are looking for `pd.cut`. Take a look at the answer on https://stackoverflow.com/questions/45273731/binning-a-column-with-python-pandas to see an example usage. You will want to change the labels from numbers to `high`, `low` etc. – rafaelc Jun 04 '22 at 20:32

1 Answers1

0

This pythonic code snippet is a way to create a new column of high and low based on the column of interest (COI) in your dataframe. Then you can run further visualization on that. It uses numpy.

import numpy as np

df['High or Low'] = np.where(
    df['COI'] >= 12, "High", np.where(
    df['COI'] <  12, "Low", -1)) 

I hope this help!