0

I have a folder with 12 .csv files which I wish to merge row by row.

This is the code I have to load one of the .csv

Code

test = pd.read_csv("D:\DAT_ASCII_EURUSD_T_201612.csv", header=None, names=['Date', 'sell_A', 'buy_A', 'unknown'], parse_dates=["Date"])

How would I merge all 12 which have the names shown below (current one is 201612);

DAT_ASCII_EURUSD_T_201601.csv DAT_ASCII_EURUSD_T_201602.csv DAT_ASCII_EURUSD_T_201603.csv DAT_ASCII_EURUSD_T_201604.csv DAT_ASCII_EURUSD_T_201605.csv DAT_ASCII_EURUSD_T_201606.csv DAT_ASCII_EURUSD_T_201607.csv DAT_ASCII_EURUSD_T_201608.csv DAT_ASCII_EURUSD_T_201609.csv DAT_ASCII_EURUSD_T_201610.csv DAT_ASCII_EURUSD_T_201611.csv DAT_ASCII_EURUSD_T_201612.csv

4
  • you could append of the files together without python, no ? or do you want to do it with python to train yourself ? Commented Aug 7, 2020 at 21:31
  • Partially to train myself but if there is a simple way not through python them open to suggestions Commented Aug 7, 2020 at 21:37
  • stackoverflow.com/questions/4969641/… Commented Aug 7, 2020 at 21:49
  • on windows: stackoverflow.com/questions/19750653/… Commented Aug 7, 2020 at 21:50

1 Answer 1

3

You can do using concat:

from pathlib import Path

# set your file path
pt = Path("your_file_path/")

name = ['Date', 'sell_A', 'buy_A', 'unknown']
df = pd.concat([pd.read_csv(file, header=None, names=name, parse_dates=["Date"]) for file in pt.glob("*.csv")])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.