Answer the question
In order to leave comments, you need to log in
Why, after changing the rows in the column and saving to csv, is the data unloaded (saved) before the changes?
Can you please tell me why, after changing the rows in the column and saving csv, the data is unloaded (saved) before the changes (that is, as if I did not make changes to the necessary rows)?
The scheme is this:
for index, row in df.iterrows():
if row.targer.str.startswith("0"):
old_result=row.result
df.loc[index, "result"] = "0"+ old_result
df.to_csv("new_df.csv", index=False)
Answer the question
In order to leave comments, you need to log in
the column was exported as a number. so zero is not displayed.
decision:
df = pd.read_csv("df.csv", dtype={"result": str})
As I understand it, this is such a test for the ability to guess what and how is written in other parts of your program.
Also, are you sure that in your code the indentation in the inner loop is exactly as you showed us?
if row.targer.str.startswith("0"):
old_result=row.result
df.loc[index, "result"] = "0"+ old_result
if row.targer.str.startswith("0"):
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question