The Python Book | |||
Latest All — By Topic 2019 2016 2015 2014 Topics:
angle argsort beautifulsoup binary bisect clean collinear covariance cut_paste_cli datafaking dataframe datetime day_of_week delta_time df2sql doctest exif floodfill fold format frequency gaussian geocode httpserver is join legend linalg links matrix max namedtuple null numpy oo osm packaging pandas plot point range regex repeat reverse sample_words shortcut shorties sort stemming strip_html stripaccent tools visualization zen zip Tags:
3d aggregation angle archive argsort atan beautifulsoup binary bisect class clean collinear colsum comprehension count covariance csv cut_paste_cli datafaking dataframe datetime day_of_week delta_time deltatime df2sql distance doctest dotproduct dropnull exif file floodfill fold format formula frequency function garmin gaussian geocode geojson gps groupby html httpserver insert ipython is join kfold legend linalg links magic matrix max min namedtuple none null numpy onehot oo osm outer_product packaging pandas plot point quickies range read_data regex repeat reverse sample sample_data sample_words shortcut shorties sort split sqlite stack stemming string strip_html stripaccent tools track tuple visualization zen zip zipfile |
delta_time
20151207
Add/subtract a delta timeProblemA number of photo files were tagged as follows, with the date and the time:
.. Turns out that they should be all an hour earlier (reminder: mixing pics from two camera's), so let's create a script to rename these files... Solution1. StartLet's use pandas:
2. Make parseableNow add a column to the dataframe that only contains the numbers of the date, so it can be parsed:
Result:
3. Convert to datetime, and subtract delta timeConvert the raw-date to a real date, and subtract an hour:
Note 20190105: apparently you can drop the 'format' string:
Result:
4. Convert adjusted date to string
We also need the 'stem' of the filename:
Result:
5. CleanupDrop columns that are no longer useful:
Result:
6. Generate scriptsGenerate the 'rename' script:
Also generate the 'rollback' script (in case we have to rollback the renaming) :
First lines of the rename script:
|