Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python equivalent to R data frames

Tags:

python

arrays

r

What is the Python equivalent to R's read.csv() function, and the data.frame it returns?

Is there a similar data structure in Python?

like image 687
N. McA. Avatar asked Sep 11 '26 07:09

N. McA.


1 Answers

Your have two elements in your question, (1) reading/writing CSV and (2) an equivalent data structure to the R data.frame that results from reading in a CSV-file.

For the first part, there is the csv module in the standard library.

For the second part, the standard library is lacking a equivalent tabular data structure with the flexibility of the the R data.frame. You have two options, depending on the complexity of the operations you will be doing afterwards:

  • A more lightweight option is tablib. It contains functions for reading/writing CSV and basic manipulations, sub-setting, etc.
  • A more comprehensive (perhaps overkill) solution is the DataFrame data structure in the pandas package. It has similar read/write functions for tabular fileformats, but has indexing/slicing, manipulation, built-in summary operations, etc. simmilar to the the R data.frame.
like image 135
mhermans Avatar answered Sep 12 '26 21:09

mhermans



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!