Fix Python – Most efficient way to find mode in numpy array

I have a 2D array containing integers (both positive or negative). Each row represents the values over time for a particular spatial site, whereas each column represents values for various spatial sites for a given time.
So if the array is like:
1 3 4 2 2 7
5 2 2 1 4 1
3 3 2 2 1 1

The result should be
1 3 2 2 2 1

Note that when there are multipl….

Fix Python – GroupBy pandas DataFrame and select most common value

I have a data frame with three string columns. I know that the only one value in the 3rd column is valid for every combination of the first two. To clean the data I have to group by data frame by first two columns and select most common value of the third column for each combination.
My code:
import pandas as pd
from scipy import stats

source = p….