, pandas inplace .update_inplace(), , , .replace() , , .
.applymap() .apply(); inplace, , .
.applymap() .apply(), .aggregate(), _aggregate(), ._agg(), , Python (.. Cython - ).
, , NumPy : :
frame = pd.DataFrame(np.random.randn(100, 100))
for i in frame.index:
for j in frame.columns:
val = round(frame.values[i,j])
frame.values[i,j] = val
newvals = np.zeros(frame.shape[1])
for i in frame.index:
for j in frame.columns:
val = round(frame.values[i,j])
newvals[j] = val
frame.values[i] = newvals
1 , - 100 ; .applymap(round) 20 .
, frame = pd.DataFrame(np.random.randn(1, 10000)), .applymap(round) 1,2 , 100 .
, frame = pd.DataFrame(np.random.randn(10000,1)) , 1s (), .applymap(round) 10 .
, .applymap .
frame.applymap(round) : (10000,1), (100,100) (1,10000). , ; , .applymap() . , .applymap(), :
newvals = np.zeros(frame.shape[1])
for i in frame.index:
for j in frame.columns:
val = round(frame.values[i,j])
newvals[j] = val
frame.values[i] = newvals
NumPy:
newvals = np.zeros(frame.shape[1])
arr = frame.values
for i in frame.index:
for j in frame.columns:
val = round(arr[i,j])
newvals[j] = val
arr[i] = newvals
100x100 300 , 60 - , .values !
Cython 34 , .applymap(round) - 24 . , .applymap() .
: , .applymap(); , , "" .
.applymap() , NumPy. - , , : . arr=df.values[i], arr, df.values[i] = arr i.