I'm doing some exercises on Udacity.
With the pandas library dealing with csv files seems super intuitive. After importing pandas as pd I can just do:
Read file
pd.read_csv("file_path")
Write file
pd.to_csv("file name")
In comparison if I import the csv library the code seems unintuitive. I have to do this:
Read file
with open("file_path", 'rb') as f:
reader = csv.reader(f)
Write file
with open("file name", 'wb') as f:
writer = csv.writer(f)
Why should I choose the csv library if if pandas read/write is so straighforward?
You should use whatever works best for you! Csv is native, so it's pretty easy to move your code to other platforms or machines. That might be an advantage in some circumstances. But if you're comfortable with panda, you should definitely use it!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With