According to the pandas documentation, Series.nonzero() is replaced by Series.to_numpy().nonzero().

Instead of

df.iloc[0].nonzero()

Try

df.iloc[0].to_numpy().nonzero()
Answer from Sabid Habib on Stack Overflow
🌐
GitHub
github.com › facebook › prophet › issues › 1408
Fbprophet error 'Series' object has no attribute 'nonzero' · Issue #1408 · facebook/prophet
March 29, 2020 - Fbprophet error 'Series' object has no attribute 'nonzero'#1408 · Copy link · akashgupta22 · opened · on Mar 29, 2020 · Issue body actions · I am trying to implement a Time Series Forecasting using FBProphet. The data is of one year of daily frequency and has 2 columns: Date and Daily Total Time ·
Author   akashgupta22
🌐
Cumulative Sum
cumsum.wordpress.com › 2022 › 06 › 11 › pandas-attributeerror-series-object-has-no-attribute
[pandas] AttributeError: 'Series' object has no attribute
June 11, 2022 - AttributeError: ‘Series’ object has no attribute ‘b’ · The reason this errors out is that agg takes a Series object as parameter instead of a sub dataframe. And a Series object doesn’t have a column b. If you have a need to access ...
Discussions

python - pandas: print names of columns with nonzero elements in row? - Stack Overflow
According to the pandas documentation, ... by Series.to_numpy().nonzero(). ... Sign up to request clarification or add additional context in comments. ... Find the answer to your question by asking. Ask question ... See similar questions with these tags. ... Stack Gives Back 2025! ... Massive loss of data unrecoverable? - sparsebundle shrank from 2 Tb to 867 Mb and is of course not ... More on stackoverflow.com
🌐 stackoverflow.com
Error in milo.make_nhoods with 'Series' object has no attribute 'nonzero'
There was an error while loading. Please reload this page · The problem seems to be at this step: dist_mat = knn_dists[nhood_ixs, :] whereby nhood_ixs is a 'Series'. It would work with: dist_mat = knn_dists[np.array(nhood_ixs), :] More on github.com
🌐 github.com
4
February 16, 2025
AttributeError: 'Series' object has no attribute [X] when preparing DataBlock - Part 1 (2020) - fast.ai Course Forums
I am having trouble running some basic code. I have a DataFrame called papers with one column called abstracts, and I am trying to create a DataBlock to load it in a model. I prepare the data (in a Kaggle notebook with the Arxiv dataset) as a Dataframe as import json data_file = '../input/... More on forums.fast.ai
🌐 forums.fast.ai
0
December 13, 2020
python - How to fix AttributeError: 'Series' object has no attribute 'to_numpy' - Stack Overflow
AttributeError: 'Series' object has no attribute 'to_numpy' More on stackoverflow.com
🌐 stackoverflow.com
🌐
GitHub
github.com › scverse › scanpy › issues › 3443
AttributeError: 'Series' object has no attribute 'nonzero' in sc.tl.filter_rank_genes_groups · Issue #3443 · scverse/scanpy
6297 6298 Parameters -> 6299 ---------- 6300 deep : bool, default True 6301 Make a deep copy, including a copy of the data and the indices. 6302 With ``deep=False`` neither the indices nor the data are copied. AttributeError: 'Series' object has no attribute 'nonzero'
🌐
GitHub
github.com › emdann › milopy › issues › 54
Error in milo.make_nhoods with 'Series' object has no attribute 'nonzero' · Issue #54 · emdann/milopy
February 16, 2025 - The problem seems to be at this step: dist_mat = knn_dists[nhood_ixs, :] whereby nhood_ixs is a 'Series'. It would work with: dist_mat = knn_dists[np.array(nhood_ixs), :] This seems to be a problem with scipy==1.15.1
Author   suochenqu
🌐
Fast.ai
forums.fast.ai › part 1 (2020)
AttributeError: 'Series' object has no attribute [X] when preparing DataBlock - Part 1 (2020) - fast.ai Course Forums
December 13, 2020 - I am having trouble running some basic code. I have a DataFrame called papers with one column called abstracts, and I am trying to create a DataBlock to load it in a model. I prepare the data (in a Kaggle notebook with the Arxiv dataset) as a Dataframe as import json data_file = '../input/arxiv/arxiv-metadata-oai-snapshot.json' def get_metadata(): with open(data_file, 'r') as f: for line in f: yield line metadata = get_metadata() titles = [] abstracts = ...
🌐
Brainly
brainly.com › computers and technology › high school › how do you fix the error: "series' object has no attribute 'columns'"?
[FREE] How do you fix the error: "Series' object has no attribute 'columns'"? - brainly.com
November 19, 2023 - To fix it, convert the Series to a DataFrame using the .to_frame() method. Alternatively, ensure you are accessing appropriate attributes for a Series, such as index or name instead of columns. The error "Series' object has no attribute 'columns'" usually occurs when working with the Pandas library in Python, indicating that a programmer is trying to access the 'columns' attribute of a Pandas Series object, which does not have this attribute...
Find elsewhere
🌐
PyTorch Forums
discuss.pytorch.org › t › attributeerror-series-object-has-no-attribute-as-matrix › 69328
AttributeError: 'Series' object has no attribute 'as_matrix' - PyTorch Forums
February 11, 2020 - When I execute the code of the official website, I get such an error. Why? code show as follow: landmarks_frame = pd.read_csv(‘F:\OfficialData\faces\face_landmarks.csv’) n = 65 img_name = landmarks_frame.iloc[n, 0] landmarks = landmarks_frame.iloc[n, 1:].as_matrix() landmarks = landmarks.astype(‘float’).reshape(-1, 2) print(‘Image name: {}’.format(img_name)) print(‘Landmarks shape: {}’.format(landmarks.shape)) print(‘First 4 Landmarks: {}’.format(landmarks[:4]))
🌐
Stack Overflow
stackoverflow.com › questions › 79364078 › infercnvpy-cnv-score-function-attributeerror-series-object-has-no-attribute
python - infercnvpy cnv_score function AttributeError: 'Series' object has no attribute 'nonzero' - Stack Overflow
I tried reinstalling all packages and python as well but nothing worked out. The error suggests that the problem is that Pandas.Series doesn't have a attribute such as nonzero, which it doesn't.
🌐
GitHub
github.com › pycaret › pycaret › issues › 746
'Series' object has no attribute '_data' -- Loaded Model fails to predict when loaded on Windows but works on Linux · Issue #746 · pycaret/pycaret
October 21, 2020 - 'Series' object has no attribute '_data' -- Loaded Model fails to predict when loaded on Windows but works on Linux#746
Author   ealvarezj
🌐
Pandas
pandas.pydata.org › pandas-docs › version › 0.25 › reference › api › pandas.Series.nonzero.html
pandas.Series.nonzero — pandas 0.25.3 documentation
>>> s = pd.Series([0, 3, 0, 4]) >>> s.nonzero() (array([1, 3]),) >>> s.iloc[s.nonzero()[0]] 1 3 3 4 dtype: int64
🌐
GitHub
github.com › CHPGenetics › GMM-Demux › issues › 2
AttributeError: 'Series' object has no attribute 'nonzero' · Issue #2 · CHPGenetics/GMM-Demux
August 5, 2020 - Hi there, I'm having an issue with running GMM-demux, I installed with pip, I've also tried installing pandas 1.1 or pandas 0.25 and have the same issue. ==============================GMM-D...
Author   mtvector
🌐
GitHub
github.com › facebook › prophet › issues › 900
Series.nonzero() deprecation warning · Issue #900 · facebook/prophet
March 22, 2019 - /home/user/lib/venvs/ts/lib/python3.5/site-packages/fbprophet/forecaster.py:880: FutureWarning: Series.nonzero() is deprecated and will be removed in a future version.Use Series.to_numpy().nonzero() instead min_dt = dt.iloc[dt.nonzero()[0]].min() using prophet version 0.4.post2 on Debian Stretch. 👍React with 👍5robnewman, pareshnakhe, raybellwaves, ericmjalbert and ciberger · No one assigned ·
Author   ispmarin
🌐
Researchdatapod
researchdatapod.com › home › how to solve python attributeerror: ‘series’ object has no attribute ‘lower’
How to Solve Python AttributeError: 'Series' object has no attribute 'lower' - The Research Scientist Pod
November 11, 2024 - AttributeError occurs in Python ... “‘Series’ object has no attribute ‘lower’” indicates that Pandas Series objects do not support lower() directly....
🌐
Saturn Cloud
saturncloud.io › blog › how-to-fix-attributeerror-series-object-has-no-attribute-tonumpy-in-pandas
How to Fix AttributeError: 'Series' Object Has No Attribute 'to_numpy' in Pandas | Saturn Cloud Blog
October 4, 2023 - The to_numpy() method is only available for DataFrame and Series objects. If you’re trying to use it on another type of object, you’ll encounter the AttributeError: 'Series' object has no attribute 'to_numpy' error.
🌐
PyTorch Forums
discuss.pytorch.org › t › attributeerror-series-object-has-no-attribute-labelnames › 162952
AttributeError: 'Series' object has no attribute 'labelNames' - PyTorch Forums
October 6, 2022 - Hello. I have some matlab files containing some matrix (x1, x2,…) and a table (called labelNames). With the following code I’m trying to access to labelNames contained in the matlab files: Folder = 'dataCubes/' # Listing all .mat files contained in dataCubes folder; hence, put all mat # ...
Top answer
1 of 3
55

As stated in another answer, the as_matrix method is deprecated since 0.23.0, so you should use to_numpy instead. However, I want to highlight the fact that as_matrix and to_numpy have different signatures: as_matrix takes a list of column names as one of its parameter, in case you want to limit the conversion to a subset of the original DataFrame; to_numpy does not accept such a parameter. As a consequence, the two methods are completely interchangeable only if you want to convert the DataFrame in full. If you (as in my case) need to convert a subset of the matrix, the usage would be quite different in the two use cases.

For example let's assume we only need to convert the subset ['col1', 'col2', 'col4'] of our original DataFrame to a Numpy array. In that case you might have some legacy code relying on as_matrix to convert, which looks more or less like:

df.as_matrix(['col1', 'col2', 'col4'])

While converting the above code to to_numpy you cannot simply replace the function name like in:

df.to_numpy(['col1', 'col2', 'col4'])  # WRONG

because to_numpy does not accept a subset of columns as parameter. The solution in that case would be to do the selection first, and apply to_numpy to the result, as in:

df[['col1', 'col2', 'col4']].to_numpy()  # CORRECT
2 of 3
22

The purpose of as_matrix method is to

Convert the frame to its Numpy-array representation.

as_matrix method is deprecated since 0.23.0
0.25.1 documentation says : Deprecated since version 0.23.0: Use DataFrame.values() instead

The two alternatives are

  1. .values() : Returns numpy.ndarray
  2. .to_numpy() : Returns numpy.ndarray

However, .values() documentation gives another warning :- Warning We recommend using DataFrame.to_numpy() instead.

I got the error in a slightly different way : AttributeError: 'DataFrame' object has no attribute 'as_matrix'