i have multiple csv files saved in one folder with the same column layout and want to load it into python as a dataframe in pandas.
The question is really simliar to this thread.
I am using the following code:
import glob
import pandas as pd
salesdata = pd.DataFrame()
for f in glob.glob("TransactionData\Promorelevant\*.csv"):
appenddata = pd.read_csv(f, header=None, sep=";")
salesdata = salesdata.append(appenddata,ignore_index=True)
Is there a better solution for it with another package?
This is taking to much time.
Thanks
To merge all CSV files, use the GLOB module. The os. path. join() method is used inside the concat() to merge the CSV files together.
I suggest use list comprehension with concat
:
import glob
import pandas as pd
files = glob.glob("TransactionData\Promorelevant*.csv")
dfs = [pd.read_csv(f, header=None, sep=";") for f in files]
salesdata = pd.concat(dfs,ignore_index=True)
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