Forums

Replace data from a data frame

Hello to the whole community: I have a question, and I want to ask for help, please. I have a data frame (With 24 columns and 12 rows) , with data between 0 and 1. The data can be for example 0 or also 0.45, etc. I need to rewrite that table, but by categories or sections, that is, for example, all the numbers that are between 0 and 0.2, replace them with 0.1. If the numbers are between 0.5 and 0.78556, it should be replaced by 0.6 (this is just an example).

How could I do it? I was thinking of something like:

for i in dataframe1[0:23]:

for j in dataframe1.index:

if 0<dataframe1.getloc[j,i]<10:

dataframe2=dataframe1.replace(dataframe1.loc[j,i],8) dataframe2

But I have not had good results.

I would appreciate any help, please.

We can help you with PythonAnywhere services here, but for general questions like that look at more general forums.