Issue
While turning around the iteration, if the conditions are satisfied then the value is changed. However, the original dataframe remains unchanged. Is there a way to solve this?
(I know itertuples, iterrows loc can available. But I want to use values. (more faster))
import panda as pd
df = pd.read_csv(filename)
for value in df.values:
if A:
value[2] = 3
print(value) # changed
df.to_csv(newfilename) # unchanged
Solution
I soled using iat.
import panda as pd
df = pd.read_csv(filename)
cnt = 0
for value in df.values:
if A:
#value[2] = 3
df[cnt, 2] = 3
print(value) # changed
cnt += 1
df.to_csv(newfilename) # changed
Additionally, iteration (sec) : df.values < itertuples < iterrows
Answered By - 최민수
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.