print is a function which always returns None, instead it writes to stdout (by default) as a side-effect. In bash and zsh (on Linux and Mac OS), you can redirect (aka save) all of a command’s stdout (aka output) to a file like this: python my-script.py > op2.csv To change your current script to w… Answer from EpicWink on discuss.python.org
🌐
Python
docs.python.org › 3 › library › csv.html
csv — CSV File Reading and Writing
Source code: Lib/csv.py The so-called CSV (Comma Separated Values) format is the most common import and export format for spreadsheets and databases. CSV format was used for many years prior to att...
🌐
GeeksforGeeks
geeksforgeeks.org › python › export-pandas-dataframe-to-a-csv-file
Export Pandas Dataframe to a CSV file - GeeksforGeeks
April 28, 2026 - The simplest way to export a DataFrame to a CSV file is by using to_csv() function without any additional parameters. This method creates a CSV file where the DataFrame's contents are written as-is.
Discussions

How to export .csv file from python and using pandas DataFrame - Stack Overflow
I am trying to export some filtered data from Python using Pandas DF to .csv file (Personal Learning project) Code : df5.to_csv(r'/C:/Users/j/Downloads/data1/export.csv') Error: Traceback (most re... More on stackoverflow.com
🌐 stackoverflow.com
CSV Export using Python - Python Scripting - Vectorworks Community Board
I'm about to start on a task for taking given named worksheet, recalculating it and then exporting the contents as a CSV. I've started at the export bit and I'll look at getting the data to go in it later. I started to use vs.PutFile, which allowed me to output a blank file, but Write, WriteLn et... More on forum.vectorworks.net
🌐 forum.vectorworks.net
October 25, 2023
Save Print output in csv file
I want to save this print output to CSV file but this code is not working, how can I save this output to CSV · In bash and zsh (on Linux and Mac OS), you can redirect (aka save) all of a command’s stdout (aka output) to a file like this: · You should open the file, then write into it (and ... More on discuss.python.org
🌐 discuss.python.org
3
0
January 11, 2022
Export results of print in csv file
Hi every one! I have result lot of rows but in csv file just one row. Why just one row in file ? It’s just example of list files in folder and subfolders. Could you please help me ? import os import csv directory = r"c:\Temp\20_MDG_Congo_MarineXII" for root, dirs, files in os.walk(directory): ... More on discuss.python.org
🌐 discuss.python.org
3
0
September 14, 2023
🌐
CodeSignal
codesignal.com › learn › courses › parsing-table-data › lessons › writing-table-data-to-csv-files-using-python
Writing Table Data to CSV Files Using Python
In this lesson, you will learn how to write table data to a CSV file using Python's built-in csv module. Throughout this course, you have been introduced to various aspects of handling table data. We've covered parsing tables from text and CSV files and writing data to text files. Now, we'll bring our knowledge full circle by exploring how to export data to a CSV file, a common data format that is widely used for data exchange between different applications and platforms.
🌐
Vectorworks Community Board
forum.vectorworks.net › home › customization › python scripting › csv export using python
CSV Export using Python - Python Scripting - Vectorworks Community Board
October 25, 2023 - I'm about to start on a task for taking given named worksheet, recalculating it and then exporting the contents as a CSV. I've started at the export bit and I'll look at getting the data to go in it later. I started to use vs.PutFile, which allowed me to output a blank file, but Write, WriteLn et...
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python › writing-csv-files-in-python
Writing CSV files in Python - GeeksforGeeks
July 12, 2025 - Ease of Use: Write data from lists or dictionaries easily using csv.writer and csv.DictWriter. By understanding and utilizing these methods, you can efficiently export your data into CSV files, making it accessible for various applications, from data analysis to data sharing.
🌐
Medium
medium.com › data-and-beyond › export-data-in-python-with-one-line-of-code-caed817c90fd
Export Data in Python with ONE LINE of Code! | by Dylan Song | Data And Beyond | Medium
December 31, 2023 - In this cell, I used the to_csv() function from Pandas, which would automatically save the Pandas dataframe as a local csv file. And the name of the csv file would be called “netflix_movies.csv” because that’s what I passed inside the ...
🌐
GeeksforGeeks
geeksforgeeks.org › pandas › saving-a-pandas-dataframe-as-a-csv
Saving a Pandas Dataframe as a CSV - GeeksforGeeks
Here, we are taking sample data to convert DataFrame to CSV. Python · import pandas as pd nme = ["Aparna", "Pankaj", "Sudhir", "Geeku"] deg = ["MBA", "BCA", "M.Tech", "MBA"] scr = [90, 40, 80, 98] data = {'Name': nme, 'Degree': deg, 'Score': scr} df = pd.DataFrame(data) df · Output: Output · Here, we simply export a Dataframe to a CSV file using df.to_csv().
Published   January 13, 2026
🌐
Python.org
discuss.python.org › python help
Save Print output in csv file - Python Help - Discussions on Python.org
January 11, 2022 - I want to save this print output to CSV file but this code is not working, how can I save this output to CSV? import csv for x in range(10, 55): print('hi', x, sep='') f = open('op2.csv', 'w') writer = csv.writer(f) writer.writerow(print()) f.close()
🌐
Medium
medium.com › @kasiarachuta › importing-and-exporting-csv-files-in-python-7fa6e4d9f408
Importing and exporting CSV files in Python | by Kasia Rachuta | Medium
May 27, 2016 - When doing data science in Python, you may be asked to analyse the data that’s in CSV or Excel file. You need to be able to read this file into Python. Using pandas will help you to automatically convert it into a DataFrame. Today, I am going to show you how to both import and export CSV files.
🌐
Python.org
discuss.python.org › python help
Export results of print in csv file - Python Help - Discussions on Python.org
September 14, 2023 - Hi every one! I have result lot of rows but in csv file just one row. Why just one row in file ? It’s just example of list files in folder and subfolders. Could you please help me ? import os import csv directory = r"c:\Temp\20_MDG_Congo_MarineXII" for root, dirs, files in os.walk(directory): for file in files: result = (file,os.path.join(root,file),os.stat(os.path.join(root,file)).st_size) print (result) with open(‘C:/Temp/20_MDG_Congo_MarineXII/opa2.csv’, ‘w’) as f: write = csv.writ...
🌐
OpenReplay
blog.openreplay.com › openreplay blog › export pandas dataframe to csv: complete guide to to_csv()
Export Pandas DataFrame to CSV: Complete Guide to to_csv()
December 21, 2024 - Yes, use `mode='a'` to append:\n\n```python\ndf.to_csv('data.csv', mode='a', header=False)\n```\n\nExclude the header to avoid repeating column names. How do I export a DataFrame to a CSV file with German locale settings?
🌐
YouTube
youtube.com › watch
Export to CSV in Python - YouTube
▶Please consider supporting me: https://www.thehardwareguy.co.uk/membershipIn this video I show you how to export data from python to a CSV file. I am runnin...
Published   February 17, 2019
🌐
Python Tutorial
pythontutorial.net › home › python basics › python write csv file
How to Write to CSV Files in Python
March 30, 2025 - Third, write data to CSV file by calling the writerow() or writerows() method of the CSV writer object.
🌐
Reddit
reddit.com › r/learnpython › saving to csv in python
r/learnpython on Reddit: Saving to CSV in Python
February 13, 2019 -

HI I am trying to save a bunch of information to a CSV file. I am scraping submissions using a keyword search and I have the title, submission id and subreddit

    submissionid= post.id
    title = post.title
    subreddit = post.subreddit

now I want to save it to a CSV. how can I do that? Pandas apparently helps with this but not sure how to go about that.

Top answer
1 of 2
3
There are several ways to do this using the standard library in python which are pretty simple. First, we should ask, what is a CSV file? Well, it's just a text file in which the first row is a header describing the names of the columns, and then an arbitrary number of rows which contain simple text values separated by a comma. All rows should end with a newline to demarcate where one row ends and another should begin. So imagine you have a bunch of scraped data with both an ID, a title and a subreddit in a nested list like so: my_data = [ [1, "Saving to CSV in Python", "learnpython"], [2, "How do I remove blank rows in a CSV in Python?", "learnpython"] ] Where each sublist in this list represents a row of data to write to the CSV file. To create a CSV file, all you really need to do is create a new file and then write the data to it, with column values separated by a comma, ending with a newline: with open('my_file.csv', 'w') as f: f.write("post_id,post_title,subreddit\n") # Write the header for row in my_data: row_text = ','.join(row) + '\n' # Create the comma-delimited row, adding a newline character so we know when a row ends f.write(row_text) It's as simple as that! Python also has a really nice CSV library which you can use to write data to a CSV file: import csv with open('my_file.csv', 'w') as f: writer = csv.writer(f) writer.writerow(["post_id","post_title","subreddit"]). # Write the header writer.writerows(my_data) # Write all of your rows to the file in one go. Either way, you end up with a file called my_file.csv which has your data in it. Note that in the above examples the indentation is important; when the with block ends, the file will be automatically closed, and you will be unable to write to it anymore. In Python, these are called context managers. Pandas is a great tool for more advanced work with data and performing analysis, but I think it's often more than is needed for simple data processing. I'd urge you explore using pure Python to solve your problems before turning to a complex library like Pandas.
2 of 2
2
Probably not worth using pandas for this small task. Have a look at the csv examples here . You may want to use the writerow method rather than writerows. If you're still stuck, report back.
🌐
Vultr Docs
docs.vultr.com › python › third-party › pandas › DataFrame › to_csv
Python Pandas DataFrame to_csv() - Export to CSV | Vultr Docs
April 10, 2025 - This optimizes the export DataFrame to CSV process, ensuring the exported file is compressed in size. The to_csv() function from Pandas is a powerful tool for saving a DataFrame to CSV in Python.
🌐
freeCodeCamp
freecodecamp.org › news › dataframe-to-csv-how-to-save-pandas-dataframes-by-exporting
Dataframe to CSV – How to Save Pandas Dataframes by Exporting
March 24, 2023 - DataFrame.to_csv(filename, sep=',', index=False, encoding='utf-8') Here, DataFrame refers to the Pandas DataFrame that we want to export, and filename refers to the name of the file that you want to save your data to.