user7468395

12 questions

1

45

views

Opposite function to utcfromtimestamp?

What is the opposite function to utcfromtimestamp()? timestamp() apparently does not take the timezone into account, as one can see in the following example: import pandas as pd import datetime start = pd.datetime(2000, 1, 1, 0, 0, 0) asFloat = start.timestamp() startDifferent = datetime.datetime.ut...
user7468395

3

53

views

Why does a conversion from np.datetime64 to float and back lead to a time difference?

With the following code, I get a two hour difference after converting back to np.datetime64. How can I avoid this? (if this should be a topic: I am presently in Central Europe) import pandas as pd import numpy as np import datetime a = np.datetime64('2018-04-01T15:30:00').astype('float') a b = np.d...
user7468395

2

90

views

How to pandadize a for loop that is dependant on the multiplication of a value from a previous row?

How can I optimize the following code so that it is quite performant for DataFrames with a lot of rows? If possible, a pandas only solution is preferred. import pandas as pd import numpy as np CONSTANT = 1 df = pd.DataFrame({'a': [7, 2, 3], 'c': [100, np.nan, np.NaN]}) df['d'] = np.nan for runner in...
user7468395

0

30

views

Show mouse position also for datetime x axis within google colab

For a matplotlib that is displayed in an external window (using matplotlib.use('TkAgg')), the following snippet shows the x/y cursor mouse hover correctly also for a datetime x axis: import matplotlib matplotlib.use('TkAgg') from datetime import datetime import matplotlib.pyplot as plt import matplo...
user7468395

1

16

views

What is the difference between scipy.signal.spectrogram and scipy.signal.stft?

The functions https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.spectrogram.html and https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.stft.html seem to do a very similar thing. What is the difference between the two functions?
user7468395

1

0

views

matplotlib's cursor info seems to be dependant from Tick resolution - how can I change this dependancy

With matplotlib, how can I see the exact value of the cursor for date values at the bottom right of the interactive plot? It seems, that this is dependent from the tick resolution: the following code example has different tick resolution. As an effect, at the bottom right of the screenshots one ti...
user7468395

1

0

views

How to avoid SettingWithCopyWarning when setting a single value?

How can I avoid the warning SettingWithCopyWarning in this case? Normally, it is enough to use a copy() of a previously created DataFrame. This does not make sense in this situation: import pandas as pd import numpy as np df = pd.DataFrame({'a': [7, 2, 3], 'b': [4, 5, 6], 'c': [np.nan, np.nan, np.N...
user7468395

1

0

views

Conversion from DatetimeIndex to datetime64[s] via int without dividing by 1e9 possible?

Is it possible to convert from a DatetimeIndex to datetime64[s] array via int array without dividing by 1e9? The following code delivers an int numpy array, but I have to divide by 1e9 to get from nanoseconds to seconds. Is it possible to take this journey (DatetimeIndex, int numpy array, and final...
user7468395

0

4

views

Event for matplotlib when finishing zoom interaction

I want to extend matplotlib using e.g. the QT4Agg or QT5Agg backend. When using the 'Zoom to rectangle' functionality: I want to get a trigger in my code when the user has finished the zooming either when the user has drawn the rectangle and matplotlib has recalculated the new view or alternative...
user7468395

1

57

views

Converting several features of a single matplotlib plot into subplots

The following snippet allows me to plot a x-axis-datetime dataframe with some convenience: import pandas as pd import matplotlib matplotlib.use('QT5Agg') font = {'family': 'DejaVu Sans', # 'normal', 'size': 8} matplotlib.rc('font', **font) import matplotlib.pyplot as plt import matplotlib.dates as...
user7468395

3

51

views

groupby(“date”) - get datetime of min and max

For this pandas DataFrame (that is in reality much longer), I would like to get the value of b and date, where b is minimum and b is maximum for that day. Performance is an issue. b date 0 1 1999-12-29 23:59:12 1 2 1999-12-29 23:59:13 2 3 1999-12-29 23:59:14 3 3 1999-12-30 23:59:1...
user7468395

1