I have three symbols with price data and successfully imported/modified that price data as shown below:
def read_files():
assets = ['ES','ZN','VX']
path = r"C:\Users\cost9\OneDrive\Documents\PYTHON\Exported_Data\%s\*.csv"
files = []
for a in assets:
files.extend(glob.iglob(path % a))
df_list = [pd.read_csv(f) for f in files]
for b in df_list:
b['Returns'] = b['Close'].pct_change()
The sample data now looks like this after creating the 'Returns' column above:
Ticker Date/Time Close Returns
ES U7 3/14/2017 5:29 2365.5
ES U7 3/14/2017 6:29 2362.25 -0.001373917
ES U7 3/14/2017 8:29 2355 -0.003069108
ES U7 3/14/2017 9:29 2359.25 0.001804671
ES U7 3/14/2017 10:29 2356 -0.001377556
ES U7 3/14/2017 11:29 2358 0.000848896
ES U7 3/14/2017 12:29 2358.5 0.000212044
ES U7 3/14/2017 13:29 2360.25 0.000741997
ES U7 3/14/2017 14:29 2360.5 0.000105921
ES U7 3/14/2017 21:29 2361.5 0.000423639
ES U7 3/14/2017 22:29 2363.5 0.000846919
ES U7 3/14/2017 23:29 2363.75 0.000105775
ES U7 3/15/2017 0:29 2364.5 0.000317292
ES U7 3/15/2017 1:29 2363.5 -0.000422922
Each of the three symbols' CSV files would look like this. Now I want to move each of these three DataFrames into separate folders:
end_path_to_csv = "C:\\Users\\cost9\\OneDrive\\Documents\\PYTHON\\Daily Tasks\\Individual Trading\\%s\CSV\\15M\\Trend_Identifier\\blah.csv"
for c in df_list:
c.to_csv(path_or_buf = end_path_to_csv % assets)
I get this error:
IOError: [Errno 2] No such file or directory: "C:\\Users\\cost9\\OneDrive\\Documents\\PYTHON\\Daily Tasks\\Individual Trading\\['ES', 'ZN', 'VX']\\CSV\\15M\\Trend_Identifier\\blah.csv"
Unfortunately I can't convert the 'assets' and 'df_list' (Dataframe) values into a dictionary - if I do that then the DataFrames won't be called and there's no csv data available.
I have three folders, each the exact same except for the symbol in the file directory, for example:
"C:\\Users\\cost9\\OneDrive\\Documents\\PYTHON\\Daily Tasks\\Individual Trading\\ES\\CSV\\15M\\Trend_Identifier\\blah.csv"
This would be for the 'ES' symbol, the 'VX' would replace 'ES' if I was referring to that DataFrame and so on.
How can I save each dataframe into the corresponding folder?
assets, rather than insertassetsinto a string.