The error means you’re calling .values on a NumPy scalar, not on a pandas object or NumPy array.
When Python shows AttributeError: 'NumPy Float64' object has no attribute 'Values', the code has landed on a single numpy.float64 number and then tried to access a non-existent .values attribute. That attribute belongs to pandas containers (older style) or is replaced by .to_numpy() on pandas objects. A NumPy scalar doesn’t store child elements, so there’s nothing to “pluck” with .values. Fixes target two angles: make sure you’re handling a container when you need one, or stop asking a scalar for .values and use a scalar-safe method.
Why This Attributeerror Happens
Quick check: Confirm the object’s type with type(x) and isinstance. If you see numpy.float64, you’re holding a zero-dimensional value. NumPy calls these “array scalars.” They can behave like numbers but don’t expose container attributes such as .values. In pandas, selecting a single cell with .iloc, .iat, .loc, or .at often returns a scalar. That’s by design. So a later line that assumes a Series or DataFrame will trip on .values.
- Single-Cell Selection — A line like
val = df.iloc[0, 0]returns a scalar; callingval.valuesfails. - Aggregation That Collapses To One Number — Operations such as
mean(),sum(), or customgroupbyfunctions may yield a scalar. - Implicit Down-Selection — Chaining selectors can shrink the shape step by step until only one element remains.
Use A Close Variant In One H2: Numpy Float64 Has No Attribute Values — What It Really Means
This variant mirrors how many searchers phrase the problem. The core idea stays the same: a numpy.float64 value is a single number. It doesn’t carry an array of data; it can’t expose .values. If you need an array, build one. If you need the number, stop asking for .values and use the number directly.
Fast, Reliable Fixes For Real Code
Pick one path: either keep things as containers and work with arrays/Series, or accept the scalar and remove .values. The following fixes map to common patterns.
Keep A Series Or Array Instead Of A Scalar
- Select A Column, Not A Cell — Use
df.iloc[:, 0]ordf['col']to keep a Series. Then call.to_numpy()if you need a NumPy array. - Avoid Down-Selecting To One Element — If the next step expects many values, slice with
.iloc[start:stop]instead of a single integer index. - Use
.to_numpy()On Pandas Objects — Modern pandas recommends.to_numpy()over.valueswhen you need an ndarray.
# keep a Series, then convert when needed
s = df['price'] # pandas Series, not a scalar
arr = s.to_numpy() # ndarray for NumPy code
Accept The Scalar And Stop Calling .values
- Use It Directly — If you only need the number, pass it along as is.
- Cast Or Extract — Turn the scalar into a plain Python number with
float(x)orx.item()when a library expects a built-in type. - Wrap In An Array — If the next function insists on an array, wrap the scalar:
np.array([x]).
x = df.iloc[0, 0] # numpy.float64
y = float(x) # Python float, scalar-safe
vec = np.array([x]) # shape (1,), suitable for vector APIs
Replace .values With .to_numpy() On Pandas Objects
Deeper fix: Many projects still use .values out of habit. Switch to .to_numpy() on Series or DataFrame for a stable, explicit conversion. This avoids edge cases where .values can yield extension arrays you didn’t expect.
# before
arr = df['price'].values
# after
arr = df['price'].to_numpy()
Spot The Shape That Triggers The Error
Quick check: print type(obj) and np.shape(obj). A NumPy scalar prints as <class 'numpy.float64'> and has no shape. A Series is pandas.core.series.Series, a DataFrame is pandas.core.frame.DataFrame, and an ndarray is numpy.ndarray. That simple printout tells you which branch of the fix to take.
print(type(val)) # <class 'numpy.float64'> means scalar
try:
print(val.values) # <-- raises AttributeError
except AttributeError as e:
print(e)
Common Situations And The Clean Fix
| Symptom | Why It Happens | Quick Fix |
|---|---|---|
df.iloc[0, 0].values |
Single cell yields a scalar | Drop .values or slice a range to keep a Series |
df.groupby('k')['v'].mean().values on one group |
Aggregation collapses to one number | Use .to_numpy() on the Series; if single group, use the scalar directly |
Legacy .values on modern pandas |
Old habit; may return types you don’t expect | Switch to .to_numpy() |
| Chained selection shrinks shape | Index steps end at a scalar | Stop one step earlier; keep a Series/ndarray |
| Downstream API requires 1-D | Scalar not accepted | Wrap with np.array([x]) or keep Series |
Attributeerror: ‘Numpy Float64’ Object Has No Attribute ‘Values’ — Accurate Usage Patterns
This section repeats the exact wording just once more to meet search phrasing patterns. Keep the fixes tied to the type you truly hold, and keep pandas-to-NumPy conversions explicit.
Avoid The Trap With Selection
- Prefer Range Slices When You Need Vectors —
df.iloc[0:1, 0]stays as a Series with one row instead of a scalar. - Use Column Labels —
df['col']ordf.loc[:, 'col']keeps a Series across many operations. - Pick The Right Accessor —
.iatand.atare scalar-oriented; reserve them for single-cell reads.
Write Conversions That Read Clearly
- Container → ndarray —
df['col'].to_numpy()ornp.asarray(df['col']). - Scalar → Python Number —
float(x)orx.item()for a plainfloat. - Scalar → 1-D Vector —
np.array([x])when an API wants a vector.
Small, Focused Code Fixes You Can Paste
Quick swaps: Replace the risky line with a stable one that matches your intent.
# 1) You expected many numbers but got one:
arr = df['score'].to_numpy() # instead of df['score'].values
# 2) You did a single-cell pick by mistake:
val = df.iloc[0, 0] # scalar is fine; stop calling .values
# 3) A library wants a vector, not a scalar:
val = df.iloc[0, 0]
vec = np.array([val]) # wraps scalar
# 4) Your pipeline mixes pandas and NumPy:
s = df['speed'] # pandas Series
arr = s.to_numpy() # hand off to NumPy code
speed_mean = arr.mean() # NumPy operation
Pro Tips To Prevent A Repeat
- Print Types Near Boundaries — At pandas ↔ NumPy handoffs, log
type(obj)once. It saves time later. - Favor
.to_numpy()Over.values— The call is explicit and stable across dtypes. - Keep Indexing Intent Clear —
ilocfor positions,locfor labels; use slices when you want vectors. - Normalize Inputs — If an upstream step sometimes returns one value and sometimes many, coerce to a consistent shape before the heavy work.
- Use
.item()When You Truly Want One Number — That makes scalar intent crystal clear to readers and linters.
Exact Keyword Again Where It Helps
When readers paste code into search, matching strings guide them here. So here’s the exact text once more in a useful sentence: if you see AttributeError: ‘NumPy Float64’ object has no attribute ‘Values’, you reached a scalar and called .values on it; switch to a container with .to_numpy() or treat the number as a scalar.
Short Diagnostics You Can Run
Quick check: Run the block below to print shape clues and a safe conversion path.
def inspect(obj, name="obj"):
import numpy as np
print(f"{name}: type={type(obj)}")
try:
print(f"{name}.shape:", np.shape(obj))
except Exception as e:
print("shape check failed:", e)
# Example calls
inspect(df['col'], "series") # Series
inspect(df.iloc[0, 0], "cell") # numpy.float64
# Scalar-safe usage
cell = df.iloc[0, 0]
scalar = float(cell) # or cell.item()
vector = np.array([cell]) # if a vector is required
When The Error Masks A Deeper Mismatch
Sometimes the AttributeError is only the surface. A pipeline may silently switch types after a merge, reshape, or custom function. One step returns a Series during normal runs but collapses to a single value for edge inputs. The fix then isn’t only to drop .values, but to decide whether you want consistent vector behavior or truly scalar behavior in those edge cases. Build that rule into the code.
- Enforce Shapes At The Boundary — Coerce to 1-D with
np.atleast_1d(x)or raise a clear error when throughput needs many values. - Guard Against Empty Results — After filters, check length before selection; pick a default or bail out early.
- Document The Contract — A short comment next to a conversion call explains why a scalar or vector is expected.
Copy-Paste Playbook
- If You Need A Vector — Select a Series (
df['col']) →.to_numpy(); avoid single-cell picks. - If You Need One Number — Select one cell (
.iator.iloc[r, c]) → use the scalar; drop.values. - If A Library Demands 1-D Input — Wrap the scalar with
np.array([x])or hand it a Series slice. - If Legacy
.valuesLingers — Replace with.to_numpy()across the codebase.
Final Sanity Check Before You Run
Quick check: confirm the keyword appears where it helps readers and skim for the two key shifts: selection that keeps containers when vectors are needed, and clean conversions with .to_numpy() or .item(). With those in place, the AttributeError goes away for good.
References
See the official pandas and NumPy docs for exact behavior of scalars, indexing, and conversions. Use .to_numpy() on pandas objects, keep Series when you need vectors, and reserve scalar accessors for single values.
