I know a question like this has been asked zillion types, but so far I have not been able to find an answer to this question.
I have joined two .csv files together with
As with @EdChum's comment, you need to use clip(upper=13)
or clip_upper(13)
. One other option which can help you in the long run with instances like this is to use apply
with a lambda function. This is a really nifty all-around method.
import pandas as pd
import numpy as np
df = pd.DataFrame(np.random.randint(5,18,size=(5, 4)), columns=list('ABCD'))
nscap = lambda x: min(x, 13)
print df.head()
print '-' * 20
df['NSCAP'] = df['D'].apply(nscap)
print df.head()
Result:
Take note of the last 2 lines of the second dataframe.
Hope this helps.