Concatenate CSV files using OS command

Viewed 89

I am trying to combine a directory of CSV files within a Python script. I have tried using Pandas to achieve this but it seems inefficient as a OS command could achieve the same thing without a library like this...

copy *.csv merged_files.csv

Is there a way to run an OS command like this inside of a Python3 script?

1 Answers

If you don't need to retrive the output of the command to put it in a variable you can simply use:

import os
os.system('your command here') 

This will make your script execute a shell command when run.

EDIT: I stumbled upon a much more well written and advanced answer from someone for sure more experienced than me on the topic, please refer to it for a more in-depth view on your question!

Related