Home>

I want to save the results of using a loop statement in python one by one in a separate csv file.

Specifically, I want to extract the data that matches the value of'code'of 5 from apple_info, save it as'code_5.csv', and repeat this up to 46.

The csv name is exported as'code_name.csv' as it is, and only the 46th result is exported.

Corresponding source code

apple_info = pd.read_csv ("apple_info.csv", encoding = "cp932")
for i in range (5,47):
print (i)
ken = apple_info [apple_info ['code'] == i]
name = i
ken.to_csv ("code_name.csv'")

What I tried Supplementary information (FW/tool version, etc.)

Please provide more detailed information here.