Selecting random rows with python and writing to a new file
The basic procedure is this:
1. Open the input file
This can be accomplished with the basic builtin open function.
2.  Open the output file
You'll probably use the same method that you chose in step #1, but you'll need to open the file in write mode.
3. Read the input file to a variable
It's often preferable to read the file one line at a time, and operate on that one line before reading the next, but if memory is not a concern, you can also read the entire thing into a variable all at once.
4.  Choose selected lines
There will be any number of ways to do this, depending on how you did step #3, and your requirements.  You could use filter, or a list comprehension, or a for loop with an if statement, etc.  The best way depends on the particular constraints of your goal.
5.  Write the selected lines
Take the selected lines you've chosen in step #4 and write them to the file.
6.  Close the files
It's generally good practice to close the files you've opened to prevent resource leaks.
I need to open a csv file, select 1000 random rows and save those rows to a new file. I'm stuck and can't see how to do it. Can anyone help?