0

I have a python script that runs a series of checks on a pandas dataframe, and prints the results of each check. The code behind each check looks a bit like this:

if sum(df["column1"]) >0:
    print("Success")
else:
    print("Failure")

What I want to do is save the results to a csv file with each result in its own cell, so that the csv looks like this:

Success
Success
Failure
Success
Failure

Does anyone know how to do this please?

3

1 Answer 1

1

You can save the results as a List and export them as pandas DataFrame to csv:

res=[]
if sum(df["column1"]) >0:
    res.append("Success")
else:
    res.append("Failure")

pd.DataFrame(res).to_csv('filename.csv',index=False,header=False)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.