The regular python int function only works for scalars. You should either use a numpy function to round the data, either

s = np.round((s - s % bucket_size) / bucket_size) #to round properly; or
s = np.fix((s - s % bucket_size) / bucket_size)   #to round towards 0

and if you actually want to convert to an integer type, use

s = s.astype(int)

to cast your array.

Answer from Andras Deak -- Слава Україні on Stack Overflow
Discussions

python - Converting series element to int - Stack Overflow
I have a pandas series- 3959 2019 Name: DATE, dtype: int64 which has only one element. I wanted to convert that element to integer. I did- for i in last_row_year.to_numpy(): last_year=i t... More on stackoverflow.com
🌐 stackoverflow.com
python - Convert all elements in float Series to integer - Stack Overflow
I have a column, having float values,in a dataframe (so I am calling this column as Float series). I want to convert all the values to integer or just round it up so that there are no decimals. More on stackoverflow.com
🌐 stackoverflow.com
March 13, 2016
convert Series float() to Series int() values?
import pandas as pd x = pd.Series([1.0, 2.0, 3.0]) print(x) # 0 1.0 # 1 2.0 # 2 3.0 # dtype: float64 x = x.astype('int') print(x) # 0 1 # 1 2 # 2 3 # dtype: int32 More on reddit.com
🌐 r/learnpython
4
1
November 12, 2019
string - Python How to convert Series type : object to int - Stack Overflow
I'm trying to convert a Series object to integer. But I'm having trouble doing it. Every time I try something I have a new Error. I tried to convert using pd.to_numeric, error while parsing string... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Microsoft Community
community.fabric.microsoft.com › t5 › Power-Query › How-to-convert-pandas-core-series-Series-to-type-int-when-I-use › td-p › 2223411
How to convert 'pandas.core.series.Series' to type 'int' when I use a python script within powerquer
December 9, 2021 - I am using a python script to manipulate data within powerquery. When I pass a table from powerquery with the column data type as 'decimal number' in powerquery, it arrives at python as of class 'pandas.core.series.Series'. If I am not mistaken, all data that passes from powerquery to python actuall...
Find elsewhere
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.Series.convert_dtypes.html
pandas.Series.convert_dtypes — pandas 3.0.6 documentation
If the dtype is numeric, and consists of all integers, convert to an appropriate integer extension type. Otherwise, convert to an appropriate floating extension type. In the future, as new dtypes are added that support pd.NA, the results of this method will change to support those new dtypes. ... >>> df = pd.DataFrame( ... { ... "a": pd.Series([1, 2, 3], dtype=np.dtype("int32")), ...
🌐
GeeksforGeeks
geeksforgeeks.org › pandas › convert-a-dataframe-column-to-integer-in-pandas
Convert a Dataframe Column to Integer in Pandas - GeeksforGeeks
March 2, 2026 - astype() method is simple and direct, ideal when you are confident all values can be converted. This method is best when the data is clean, and you are sure that all values in the column can be successfully converted to integers without any errors.
🌐
Stack Overflow
stackoverflow.com › questions › 55682343 › series-value-from-object-to-int
python - Series value from object to int? - Stack Overflow
If you were instead looking to filter things out of the set, I would use the filter() function using a function that returns true if the type you want and pass in the series. def isInt(element): return type(element) == 'int' filter(isInt, df) #do what you want after this assuming all elements are ints ... Sign up to request clarification or add additional context in comments. ... So how would I create a new df that includes the int values of the old df and also the converted object to int values of the old df?
🌐
Spark By {Examples}
sparkbyexamples.com › home › pandas › pandas series astype() function
Pandas Series astype() Function - Spark By {Examples}
June 18, 2024 - In pandas, the astype() method is used to cast a pandas object (like a Series or DataFrame) to a specified data type. This method is particularly useful
🌐
Pandas
pandas.pydata.org › pandas-docs › stable › reference › api › pandas.to_numeric.html
pandas.to_numeric — pandas 3.0.2 documentation - PyData |
Convert dtypes. ... >>> s = pd.Series(["1.0", "2", -3]) >>> pd.to_numeric(s) 0 1.0 1 2.0 2 -3.0 dtype: float64 >>> pd.to_numeric(s, downcast="float") 0 1.0 1 2.0 2 -3.0 dtype: float32 >>> pd.to_numeric(s, downcast="signed") 0 1 1 2 2 -3 dtype: int8 >>> s = pd.Series(["apple", "1.0", "2", -3]) >>> pd.to_numeric(s, errors="coerce") 0 NaN 1 1.0 2 2.0 3 -3.0 dtype: float64
🌐
Saturn Cloud
saturncloud.io › blog › pandas-convert-string-to-int-a-guide-for-data-scientists
Pandas Convert String to Int A Guide for Data Scientists | Saturn Cloud Blog
May 1, 2026 - To convert a string to an integer using Pandas, you can use the astype() method. This method is available on Pandas Series and DataFrame objects and can be used to convert the data type of a column from one type to another.
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.to_numeric.html
pandas.to_numeric — pandas 3.0.6 documentation - PyData |
Convert dtypes. ... >>> s = pd.Series(["1.0", "2", -3]) >>> pd.to_numeric(s) 0 1.0 1 2.0 2 -3.0 dtype: float64 >>> pd.to_numeric(s, downcast="float") 0 1.0 1 2.0 2 -3.0 dtype: float32 >>> pd.to_numeric(s, downcast="signed") 0 1 1 2 2 -3 dtype: int8 >>> s = pd.Series(["apple", "1.0", "2", -3]) >>> pd.to_numeric(s, errors="coerce") 0 NaN 1 1.0 2 2.0 3 -3.0 dtype: float64