You can convert a string to a file object using io.StringIO and then pass that to the csv module:

from io import StringIO
import csv

scsv = """text,with,Polish,non-Latin,letters
1,2,3,4,5,6
a,b,c,d,e,f
gęś,zółty,wąż,idzie,wąską,dróżką,
"""

f = StringIO(scsv)
reader = csv.reader(f, delimiter=',')
for row in reader:
    print('\t'.join(row))

simpler version with split() on newlines:

reader = csv.reader(scsv.split('\n'), delimiter=',')
for row in reader:
    print('\t'.join(row))

Or you can simply split() this string into lines using \n as separator, and then split() each line into values, but this way you must be aware of quoting, so using csv module is preferred.

On Python 2 you have to import StringIO as

from StringIO import StringIO

instead.

Answer from Michał Niklas on Stack Overflow
🌐
Python
docs.python.org › 3 › library › csv.html
csv — CSV File Reading and Writing
Return a reader object that will process lines from the given csvfile. A csvfile must be an iterable of strings, each in the reader’s defined csv format. A csvfile is most commonly a file-like object or list.
Discussions

Function to read csv string
Have you actually tried solving this without any packages? Where are you stuck? More on reddit.com
🌐 r/learnpython
2
0
August 22, 2021
python - Parsing CSV string with CSV module - Stack Overflow
I'm getting CSV formatted data piped from an external source, and the data should not be written to a file, that would open a number of different maintenance tasks I would like to avoid. I am getting the data as a string. So now I want to interpret the data as CSV. The python module csv is suited for that, so I am using it. However, constructing a CSV parser using csv.reader ... More on stackoverflow.com
🌐 stackoverflow.com
Parsing a csv file with specific criteria
CSV files only contain strings. You will need to convert field values before you can make numerical comparisons. The error you're describing looks like you're trying to treat the list like a dictionary. Try using csv.DictReader() instead of csv.Reader(). The you don't need a nested loop and can instead call the values by column name. Say, the value you want to test is in a column called "score", you could do something like: reader = csv.DictReader(csvfile) for row in reader: if float(row["score"] ) >= 98: print("Success") More on reddit.com
🌐 r/learnpython
3
0
October 28, 2021
When using reader or DictReader from the csv module, why do you need to access the return value while the file is still open?
because leaving the with-block calls the object's __exit__() function https://peps.python.org/pep-0343/ which for a filehandle is equivalent to a close() https://docs.python.org/3/reference/datamodel.html#object.__exit__ so after you jump out of the with-block's indent, the file handle's close function has been called and it's no longer readable More on reddit.com
🌐 r/learnpython
11
3
August 7, 2023
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.read_csv.html
pandas.read_csv — pandas 3.0.4 documentation - PyData |
Read a comma-separated values (csv) file into DataFrame. Also supports optionally iterating or breaking of the file into chunks. Additional help can be found in the online docs for IO Tools. ... Any valid string path is acceptable. The string could be a URL. Valid URL schemes include http, ftp, s3, gs, and file.
🌐
w3resource
w3resource.com › python-exercises › modules › python-module-csv-exercise-3.php
Python: Parse a given CSV string and get the list of lists of string values - w3resource
August 11, 2025 - import csv csv_string = """1,2,3 4,5,6 7,8,9 """ print("Original string:") print(csv_string) lines = csv_string.splitlines() print("List of CSV formatted strings:") print(lines) reader = csv.reader(lines) parsed_csv = list(reader) print("\nList representation of the CSV file:") print(parsed_csv) ... Original string: 1,2,3 4,5,6 7,8,9 List of CSV formatted strings: ['1,2,3', '4,5,6', '7,8,9'] List representation of the CSV file: [['1', '2', '3'], ['4', '5', '6'], ['7', '8', '9']] ... Write a Python program to parse a multiline CSV string using csv.reader and output the result as a list of lists.
🌐
Spark By {Examples}
sparkbyexamples.com › home › pandas › how to read csv from string in pandas
How to Read CSV from String in Pandas - Spark By {Examples}
December 11, 2024 - Do Pandas read/import CSV from the string? We are often required to read a CSV file but in some cases, you might want to import from a String variable
🌐
Compciv
2017.compciv.org › guide › topics › python-standard-library › csv.html
csv - reading and writing delimited text data
Or you can store it in a string, with the variable name of rawtext. I’ll assume that for the remainder of this exercise, you have a variable named records which is the result of either of these data loading steps: The csv.reader() function accepts either a file object, or a list of CSV-formmated ...
🌐
Reddit
reddit.com › r/learnpython › function to read csv string
r/learnpython on Reddit: Function to read csv string
August 22, 2021 -

I am trying to create a function which takes a string input in csv format. For example ```"id,name,age,score\n1,Jack,NULL,12\n17,Betty,28,11" ```.

It should return the follow table

id name age score
1 Jack NULL 12
17 Betty 28 11

It should also remove the defective rows. A defective row is when it has value **NULL**. sensitive to capital letters. any other characters like (0 to 9 or a to z or A to Z) is acceptable.

The final output from the above input string should be

id name age score
17 Betty 28 11

Here is my code using ```pandas and csv``` packages. I need to create this without using any of these packages.

```

def test(S):

result = pd.DataFrame(csv.reader(S.splitlines()))

new_header = result.iloc[0]

result = result[1:]

result.columns = new_header

df = result.select_dtypes(object)

new_result = ~df.apply(lambda series: series.str.contains('NULL')).any(axis=1)

f_result = result[new_result]

return f_result

```

Find elsewhere
🌐
Statology
statology.org › home › how to read csv file from string into pandas dataframe
How to Read CSV File from String into Pandas DataFrame
January 6, 2023 - This tutorial explains how to read a CSV file from a string in pandas, including several examples.
🌐
Roy Tutorials
roytuts.com › home › python › how to read csv file or string using python
How to read CSV file or string using Python - Roy Tutorials
May 30, 2022 - import csv with open('sample.csv', newline='') as csvfile: reader = csv.DictReader(csvfile) for row in reader: print(row['policyID'], row['statecode'], row['county']) The above example will give you the same output though I am printing only ...
🌐
Penn State University
e-education.psu.edu › geog485 › node › 283
4.3 Reading and parsing text using the Python csv module | GEOG 485: GIS Programming and Software Development
The header line of a CSV file is different from the other lines. It gets you the information about all the field names. Therefore, you will examine this line a little differently than the other lines. First, you advance the CSV reader to the header line by using the next() method, like this: ... This gives you back a Python list of each item in the header. Remember that the header was a pretty long string ...
🌐
Ars OpenForum
arstechnica.com › forums › operating systems & software › programmer's symposium
Python csv module: Reading from a string instead of a file | Ars OpenForum
January 26, 2007 - </div></BLOCKQUOTE><BR>I believe in the current cPython implementation that the file handle will always be closed after the csv reader completes, since the file object is then unreachable.<BR><BR>It still is good practice to close it explicitly, but in Python you can get away with a lot without explicitly closing files. ... <pre class="ip-ubbcode-code-pre"> import csv, StringIO data = """date,id,weight 01/01/1991,2dj392,293 01/02/1991,2dj392,291 01/03/1991,2dj392,289 """ reader = csv.reader(StringIO.StringIO(data), csv.excel) print reader for i in reader: print i </pre>
🌐
Real Python
realpython.com › python-csv
Reading and Writing CSV Files in Python – Real Python
January 25, 2023 - Each row returned by the reader is a list of String elements containing the data found by removing the delimiters. The first row returned contains the column names, which is handled in a special way. Rather than deal with a list of individual String elements, you can read CSV data directly into a dictionary (technically, an Ordered Dictionary) as well.
🌐
SwCarpentry
swcarpentry.github.io › web-data-python › 02-csv
Working With Data on the Web: Handling CSV Data
August 14, 2016 - Test a program that parses CSV using multiline strings. Our little program gets the data we want, but returns it as one long character string rather than as a list of numbers. There are two ways we could convert the former to the latter: Write a function to split that string on newline characters to create lines, then split the lines on commas and convert the second part of each to a number. Use a python library to do this for us.
🌐
Python
docs.python.org › 3.4 › library › csv.html
14.1. csv — CSV File Reading and Writing — Python 3.4.10 documentation
June 19, 2020 - Each row read from the csv file is returned as a list of strings. No automatic data type conversion is performed unless the QUOTE_NONNUMERIC format option is specified (in which case unquoted fields are transformed into floats). ... >>> import csv >>> with open('eggs.csv', newline='') as csvfile: ... spamreader = csv.reader(csvfile, delimiter=' ', quotechar='|') ...
🌐
University of Washington
courses.cs.washington.edu › courses › cse140 › 13wi › csv-parsing.html
How to parse csv formatted files using csv.DictReader?
Your Python code must import the csv library. ... Open the file by calling open and then csv.DictReader. ... You may iterate over the rows of the csv file by iterating ove input_file. (Similarly to other files, you need to re-open the file if you want to iterate a second time.) ... When you iterate over a normal file, each iteration of the loop produces a single string that represents the contents of that line.
🌐
TutorialsPoint
tutorialspoint.com › How-to-convert-a-Python-csv-string-to-array
How to convert CSV columns to text in Python?
May 7, 2025 - Load the CSV file into a pandas DataFrame using the read_csv() function. Extract the desired column from the DataFrame using indexing, and convert it to text using astype(str). Join the resulting strings using the join() method to create a single ...
🌐
GeeksforGeeks
geeksforgeeks.org › pandas › reading-csv-files-in-python
Reading CSV files in Python - GeeksforGeeks
May 25, 2026 - The csv.reader() function reads the CSV file line by line and returns each row as a list. It is useful when we want simple row-wise access to CSV data. ... Each row is returned as a list and for loop prints every row from the CSV file.
🌐
Analytics Vidhya
analyticsvidhya.com › home › read csv files in python
Read CSV Files in Python - Analytics Vidhya
January 9, 2026 - A. There are many ways to read CSV files as plain text in Python including using csv.reader, .readlines(), pandas, or csv.DictReader.