Fix Python – extracting days from a numpy.timedelta64 value

I am using pandas/python and I have two date time series s1 and s2, that have been generated using the ‘to_datetime’ function on a field of the df containing dates/times.
When I subtract s1 from s2

s3 = s2 – s1

I get a series, s3, of type

timedelta64[ns]

0 385 days, 04:10:36
1 57 days, 22:54:00
2 642 days, 21:15:23
3 615 days, 00….

Fix Python – Mocking boto3 S3 client method Python

I’m trying to mock a singluar method from the boto3 s3 client object to throw an exception. But I need all other methods for this class to work as normal.
This is so I can test a singular Exception test when and error occurs performing a upload_part_copy
1st Attempt
import boto3
from mock import patch

with patch(‘botocore.client.S3.upload_part_co….

Fix Python – How to kill a while loop with a keystroke?

I am reading serial data and writing to a csv file using a while loop. I want the user to be able to kill the while loop once they feel they have collected enough data.
while True:
#do a bunch of serial stuff

#if the user presses the ‘esc’ or ‘return’ key:
break

I have done something like this using opencv, but it doesn’t seem to….

Fix Python – How to rename a virtualenv in Python?

I misspelled the name of the virtualenv while initializing it using:
$ virtualenv vnev

I actually intended to create the environment with the name venv.
Having tried to rename the vnev folder to venv, I find that this doesn’t provide much help. The name of the activate environment still renames the old vnev.
$ mv vnev venv
$ . venv/bin/activate
(….

Fix Python – Specify format of floats for tick labels

I am trying to set the format to two decimal numbers in a matplotlib subplot environment. Unfortunately, I do not have any idea how to solve this task.
To prevent using scientific notation on the y-axis I used ScalarFormatter(useOffset=False) as you can see in my snippet below. I think my task should be solved by passing further options/arguments ….