How do I read .csv files

Benjamin Schollnick bschollnick at schollnick.net
Tue Mar 16 09:23:08 EDT 2021


The best answer is to use the CSV library, but there are wrappers around it.

For example, I use a wrapper of my own creation (csv_common.py) @ https://github.com/bschollnick/bas_Utilities <https://github.com/bschollnick/bas_Utilities>.
The main benefit is that I can create variant CSV’s by just inheriting and redefining portions of it, very quickly.  

But, Panda’s and other tools are just as valid as well.

But I would really recommend playing with the CSV library first, and understand how it works, before using a wrapper or a totally different tool.  Understanding the basics really simplifies the learning process, and gives you a foundation to build upon.

	- Benjamin

> On Mar 16, 2021, at 8:23 AM, Gys <invalid at invalid.com> wrote:
> 
> On 3/12/21 11:28 AM, Johann Klammer wrote:
>> Specifically ones with quoted strings. I'll have whitespace in
>> there and possibly escaped quotechars.
>> maybe newlines too.
>> Which means that pyparsing commaSeparatedList.parseString(line) won't work.
>> I also like to edit them for visual alignment, so there'll
>> be whitespaces outside the strings(more than one)
>> ...therefore, csv.DictReader() won't work.
>> I'd like them read into a dict or something..
> 
> Hi Johann Klammer,
> I use Pandas for handling *.csv files
> 
> pandas documentation :
> 
> <https://pandas.pydata.org/pandas-docs/stable/index.html>
> 
> Hands on example :
> 
> <https://chrisalbon.com/python/data_wrangling/pandas_dataframe_importing_csv/>
> 
> -hth
> Gys
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list