# user7468395

10 questions

1

votes

2

answer

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...

1

votes

0

answer

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...

2

votes

1

answer

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?

1

votes

1

answer

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...

1

votes

1

answer

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...

1

votes

1

answer

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...

0

votes

0

answer

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...

1

votes

1

answer

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...

1

votes

3

answer

50

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...

1

votes

1

answer

22

views

### How can I assign the contents of a pandas series to a sqlAlchemy class instance without boilerplate code?

For the following example, I have to assign every single field of the pandas series to the class instance.
Is there any way to do this in a single step (like: abc = Abc(series)
import pandas as pd
from sqlalchemy import Column, Integer, String, Boolean
from sqlalchemy.dialects.mysql import DATETIME...