So I have several years of weekly CSV files that look like, with in the form YYmmdd:
file = 'C:\\rig-070103'
I am trying to read and combine them into one dataset, preferably over a range of dates. So far I have:
pieces = []
for date in range(100):
path = 'C:\\rig-YYmmdd.csv' % date
frame = pd.read_csv(path)
#frame['Date']= date
pieces.append(frame)
dataset = pd.concat(pieces, ignore_index=True)
print(dataset)
But this is giving me the error:
path = 'C:\\rig-YYmmdd.csv' % date
TypeError: not all arguments converted during string formatting
I know this has to do with how I am referencing each file, any suggestions? I would also like to create another column listing the date for each file loaded in, so 1 date repeated over all rows for each file. Any help on this is really appreciated!
Here is an example of the data:
Prov Location LSD Section Township Range Meridian ...
AB 00-00-006-29W4 0 0 6 29 4
AB 01-18-008-09W4 1 18 8 9 4
AB 05-10-008-10W4 5 10 8 10 4
AB 01-12-008-12W4 1 12 8 12 4
AB 09-23-008-26W4 9 23 8 26 4
AB 13-13-009-25W4 13 13 9 25 4
Couple of things going on here:
First,
for date in range(100)will iterate through integers 0 through 99. No dates anywhere to be found.Next,
path = 'C:\\rig-YYmmdd.csv' % dateisn't valid. Assuming you actually have adatetimeobject, you would do:path = 'C:\\rig-%s.csv' % date.strftime('%y%m%d')Finally, you're writing/overwriting your dataframe with every iteration. That silly.
So you your code becomes