Assuming the CSV file is delimited with commas, the simplest way using the csv
module in Python 3 would probably be:
import csv with open('testfile.csv', newline='') as csvfile: data = list(csv.reader(csvfile)) print(data)
You can specify other delimiters, such as tab characters, by specifying them when creating the csv.reader
:
data = list(csv.reader(csvfile, delimiter='\t'))
For Python 2, use open('testfile.csv', 'rb')
to open the file.[
Related Posts:
- How to read a CSV file from a URL with Python?
- TypeError: list indices must be integers or slices, not str
- What is the difference between rw+ and r+
- Writing a pandas DataFrame to CSV file
- Writing a pandas DataFrame to CSV file
- raw_input function in Python
- IndexError: too many indices for array
- ValueError : I/O operation on closed file
- write() versus writelines() and concatenated strings
- Pandas: ValueError: cannot convert float NaN to integer
- csv.Error: iterator should return strings, not bytes
- No module named MySQLdb
- No module named MySQLdb
- How do you use subprocess.check_output() in Python?
- Python – Reading and writing csv files with utf-8 encoding
- Python Error io.UnsupportedOperation: not readable
- How can I concatenate str and int objects?
- load csv into 2D matrix with numpy for plotting
- Dump a NumPy array into a csv file
- (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3: truncated \UXXXXXXXX escape
- How to load a tsv file into a Pandas DataFrame?
- How do you use subprocess.check_output() in Python?
- Difference between writerow() and writerows() methods of Python csv module
- Create a .csv file with values from a Python list
- Convert XML to CSV file
- TypeError: list indices must be integers or slices, not str
- Convert from CSV to array in Python
- ValueError: cannot index with vector containing NA / NaN values
- (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3: truncated \UXXXXXXXX escape
- Creating a dictionary from a csv file?
- Python import csv to list
- Python – ‘ascii’ codec can’t decode byte
- How to return dictionary keys as a list in Python?
- ValueError: x and y must be the same size
- UnicodeEncodeError: ‘ascii’ codec can’t encode character u’\xa0′ in position 20: ordinal not in range(128)
- OSError: Initializing from file failed on csv in Pandas
- append new row to old csv file python
- Writing a dictionary to a csv file with one line for every ‘key: value’
- Python CSV error: line contains NULL byte
- Python CSV Error: sequence expected
- AttributeError: ‘float’ object has no attribute ‘split’4
- How to add pandas data to an existing csv file?
- convert csv file to list of dictionaries
- _csv.Error: field larger than field limit (131072)
- TypeError: super() takes at least 1 argument (0 given) error is specific to any python version?
- CSV new-line character seen in unquoted field error
- What exactly do “u” and “r” string flags do, and what are raw string literals?
- Determine if 2 lists have the same elements, regardless of order? [duplicate]
- Writing Python lists to columns in csv
- Using print() (the function version) in Python2.x
- Error in Reading a csv file in pandas[CParserError: Error tokenizing data. C error: Buffer overflow caught – possible malformed input file.]
- How to iterate over rows in a DataFrame in Pandas
- How to convert list to string [duplicate]
- How to uninstall a package installed with pip install –user
- ModuleNotFoundError: No module named ‘sklearn’
- Does Python have an ordered set?
- Asking the user for input until they give a valid response
- Print a list in reverse order with range()?
- Configuring so that pip install can work from github
- Proper way to declare custom exceptions in modern Python?
- TypeError: ‘float’ object not iterable
- How to read a .xlsx file using the pandas Library in iPython?
- Numpy/Python Array Value error
- Changing the “tick frequency” on x or y axis in matplotlib?
- TypeError: unsupported operand type(s) for -: ‘str’ and ‘str’
- Remove all special characters, punctuation and spaces from string
- AttributeError: ” object has no attribute ”
- Plot pie chart and table of pandas dataframe
- ModuleNotFoundError: No module named ‘matplotlib’
- “inconsistent use of tabs and spaces in indentation”
- python object() takes no parameters error
- How do I find the distance between two points?
- How do I calculate percentiles with python/numpy?
- How do I remove a substring from the end of a string?
- Selecting with complex criteria from pandas.DataFrame
- How can I download Anaconda for python 3.6
- How to make a histogram from a list of data
- Using __add__ operator with multiple arguments in Python
- How to constantly run Python script in the background on Windows?
- Django – “no module named django.core.management”
- Windows path in Python
- Python: ValueError: Mixing iteration and read methods would lose data
- python: restarting a loop
- “for loop” with two variables?
- Display number with leading zeros
- Running Python in PowerShell?
- Why do many examples use `fig, ax = plt.subplots()` in Matplotlib/pyplot/python
- ImportError: No module named model_selection
- Numpy – add row to array
- How to change pip installation path
- What is the difference between a string and a byte string?
- Rolling or sliding window iterator?
- What is a namespace object?
- How to serve static files in Flask
- How to create Gephi network graphs from Python?
- strncmp in python
- Is it possible to forward-declare a function in Python?
- Python OpenCV2 (cv2) wrapper to get image size?
- KeyError: ‘plotly_domain’
- The value of _stdout is incorrect