1
for i in range(1,151):
 Path = './Result/Normal_%d'%i
 Normal_i.to_csv(Path, sep=',' , header=None , index=None)

I would like to use for loop to save a file that is name Normal_1, Normal_2 ...Normal_150 and I found out that using "Normal_i" in for loop makes an error. What Can I do to save a file that is named Normal_1, Normal_2 in for loop?

1
  • What error did you get? Commented Aug 5, 2021 at 8:28

2 Answers 2

1
Path = './Result/Normal'
for i in range(1,151):
 Normal_i.to_csv(Path+str(i), sep=',' , header=None , index=None)
Sign up to request clarification or add additional context in comments.

Comments

0

A good answer has already been given, but here is a fun python thing you could try:

eval(f"Normal_i.to_csv({Path}File{i}, sep=',' , header=None , index=None)")

About eval().

PS: I do not endorse doing this.

3 Comments

Why to use eval unnecessarily?
eval is the opposite of pythonic. It's like using an excavator to hammer down a nail.
You should read this: Eval really is dangerous

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.