Skip to content
Advertisement

This single line “import seaborn as sns” dumps a dataframe to standard out?

This is literally the only command I’m running:

import seaborn as sns

When I run that single line of code the computer prints out a dataframe from a previous program:

# MEAN
A12    42.297308
A1     42.044986
A6     42.966379
Name: MEAN, dtype: float64

As well as an error

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "PLOTS/seaborn.py", line 40, in <module>
    sns.barplot(x = 'X', y = 'Y', data = plotMe)
AttributeError: module 'seaborn' has no attribute 'barplot'

It’s like it’s running another script on the computer that I wrote. I’ve rebooted my computer multiple times. Powered off and unplugged it for a while… etc. The same thing happens when I either run it as an interactive shell:

python
>>> import seaborn as sns

or put that single line in a script and run it that way.

python test.py

Any clue what’s going on? I’m running Python 3.6.9

Advertisement

Answer

It’s like it’s running another script on the computer that I wrote

It is running another script you (probably) wrote. It’s running PLOTS/seaborn.py. When you import a package or modules, Python searches a range of places of that module (the search paths are stored in sys.path). The first place it looks is the current working directory. Importing a script executes it, hence what you see is the result of PLOTS/seaborn.py.

For this reason, it is a good idea not to save files with the same names as packages you want to import! Just rename or move PLOTS/seaborn.py and you should be fine.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement