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 codeapple_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'")
Please provide more detailed information here.
-
Answer # 1
Related articles
- i have a question about basic python problems
- about python argument and data definition
- python 3x - please teach about the exchange of information with qthead
- python - about x-axis adjustment in matplotlib
- python - i want to eliminate an infinite loop
- python - about "" "of" "" select === = "" "
- python, about the fire spread step of forest fire simulation
- python - about hamiltonian neural networks
- python 3x - about downloading anaconda
- python 3x - about functions used in python for statement
- python - about the optimum angle of rotation matrix
- python - about downloading youtube videos by youtube-dl
- about processing to exclude the character string group specified from list in python
- python - what i don't understand about yolo9000 (v2)
- python - how to keep getting csv data in a loop
- python - read and write values from another file
- about batch change of file name using python
- about image output of python
- python 3x - about the amount of data for object detection using machine learning
Related questions
- python : The problem that the string becomes a date in csv
- python : How to read only the required columns of a table in a CSV file?
- python : Error when serializing json from file
- Changing an element in a data file using Python
- python : How to set a date condition in a query with where? [duplicate]
- python : How to make it so that after processing each line in the .csv file, it deletes the previous one?
- python : how to save a dictionary in csv in each line, I get it through a line when I open it through Excel
If you want to embed the value of the name variable in the destination filename, you need to do that.
There are several ways to write it, but with python3,
You can do it like this. Also pay attention to "f".