Q:

Subtract from each cell in pandas dataframe based on value

I have a df like this-- it's a dataframe and all values are floats:
data=np.random.randint(3000,size=(10,1))
data=pd.DataFrame(data)

For each value, if it's between 570 and 1140, I want to subtract 570.
If it's over 1140, I want to subtract 1140 from the value. I wrote this function to do that.
 def AdjustTimes(val):
         if val > 570 and val < 1140:
             val = val-570
         elif val > 1140:
             val = val - 1140

Based on another question I tried to apply it using data.applymap(AdjustTimes). I got no error but the function does not seem to have been applied.

A:

Setup
data

      0
0  1863
1  2490
2  2650
3  2321
4   822
5    82
6  2192
7   722
8  2537
9   874

First, let's create masks for each of your conditions. One pandaic approach is using between to retrieve a mask for the first condition - 
m1 = data.loc[:, 0].between(570, 1140, inclusive=True)

Or, you can do this with a couple of logical operators - 
m1 = data.loc[:, 0].ge(570) & data.loc[:, 0].le(1140)

And,
m2 = data.loc[:, 0].gt(1140)

Now, to perform replacement, you have a couple of options.
Option 1
Use loc to index and subtract - 
data.loc[m1, 0] -= 570
data.loc[m2, 0] -= 1140

data

      0
0   723
1  1350
2  1510
3  1181
4   252
5    82
6  1052
7   152
8  1397
9   304

Equivalent version for a pd.Series - 

m1 = data.ge(570) & data.le(1140)
m2 = data.gt(1140)

data.loc[m1] -= 570
data.loc[m2] -= 1140

Option 2
You can also do this with np.where (but it'd be a bit more inefficient). 
v = data.loc[:, 0]
data.loc[:, 0] = np.where(m1, v - 570, np.where(m2, v - 1140, v))

Here, m1 and m2 are the masks computed from before.

data

      0
0   723
1  1350
2  1510
3  1181
4   252
5    82
6  1052
7   152
8  1397
9   304

Equivalent pd.Series code - 

data[:] = np.where(m1, data - 570, np.where(m2, data - 1140, data))

