1

I have some paramters

p=221
q=4.22
r=3.3

I want to save my output values in file named as p_221__q_4.22__r_3.3.csv i tried this

file_name = open('p_{}__q_{}__r_{}.csv'.format(p,q,r),'w')
output.to_csv(filename+'.csv', index=False)

but error came as "Replacement index 2 out of range for positional args tuple"

2
  • what format is your output variable? Is it a pandas dataframe? Commented Dec 7, 2020 at 17:44
  • yes output is a pandas dataframe Commented Dec 7, 2020 at 17:51

1 Answer 1

1

If your output variable is a pandas dataframe, just use the to_csv() function:

p=221
q=4.22
r=3.3
output = pd.DataFrame([p,q,r])

file_name = 'p_{}__q_{}__r_{}.csv'.format(p,q,r)
output.to_csv(file_name)

Using the to_csv() function precludes the need to open any file using open()

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.