ERJAN
ERJAN

Reputation: 24500

How to properly import scatter_matrix() function from pandas?

It does not see the scatter_matrix, says "not found":

import pandas.plotting
scatter_matrix(df[['col1', 'col2']])

I tried this:

import pandas.plotting.scatter_matrix
ImportError: No module named 'pandas.plotting.scatter_matrix'

actually when I hit tab after "plotting." the popup hint for import is showing some functions to import but no scatter_matrix

But doing this works and plots:

pandas.plotting.scatter_matrix(df[['col1', 'col2']])

Why do i Need the whole path to use scatter_matrix? How to import the scatter_matrix?

Upvotes: 1

Views: 1173

Answers (1)

Yoel Nisanov
Yoel Nisanov

Reputation: 1054

Simply change it from

import pandas.plotting.scatter_matrix

to

from pandas.plotting import scatter_matrix

When you're importing you import a file, if you want to import specific function you must specify from what file you want to import it (:

Edit:

There are generally two types of import syntax. When you use the first one, you import the resource directly, like this:

import abc
abc can be a package or a module.

When you use the second syntax, you import the resource from another package or module. Here’s an example:

from abc import xyz

xyz can be a module, subpackage, or object, such as a class or function.

reference- https://realpython.com/absolute-vs-relative-python-imports/

Upvotes: 1

Related Questions