So I installed pandas and I can run these first two lines no problem:
import pandas as pd
import numpy as np
But this line:
pd.read_csv('train.csv', header=0)
gives me the following error:
AttributeError: 'module' object has no attribute 'read_csv'
Is there something wrong with the module?
I am running Python 2.7.5 with Mac OS X 10.9.2
Your input is appreciated!
EDIT: I was running a file named pandas.py, which is the same name as the 'pandas' module, hence the error.
Related
When I load python (a fresh env, using conda, or similar) and try:
import pandas
I get this error:
AttributeError: partially initialized module 'pandas' has no attribute 'DataFrame' (most likely due to a circular import)
>>> import pandas as pd
In this case it was due to there being csv.py file in the current directory.
I am currently working with netCDF data in the Spyder IDE, however when I try to import 'Dataset' from the module
from netCDF4 import Dataset
it is giving me the following error: "No module named 'netCDF4'". I already installed the module but I guess it is not in the same environment where I installed spyder. How can I fix this? If it helps solving my question. When I try to install netCDF4 in the spyder console using 'pip install netCDF4' it gives the following error:
"/Applications/Spyder.app/Contents/MacOS/python: No module named pip
Note: you may need to restart the kernel to use updated packages."
I looked up the path of the module: '/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/netCDF4'
and I guess the path for spyder is:
'/Applications/Spyder.app/Contents/MacOS/python'
How can I make sure that they are both located in the same environment?
I tried to look up the issue, however nothing really solved my problem.
Would be glad if anyone could help me out.
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
from netCDF4 import Dataset
from cftime import numb2date
import tifffile as tifffile
# define arrays
XNR=[] # number
Xdt=[] # time
YGP=[] # GPP
YPP=[] # PPFD
# read csv file and extract column 0 (timestemp), PPFD (column 54) and GPP (column 312)
# take a file from FLUXNET for validation of the GPP model
with open(r'/Users/janoschbeer/Documents/Studium/ESS/ES_Observ/Assignments/Lab6/FLX_SJ-Adv_FLUXNET2015_SUBSET_2011-2014_1-4/FLX_SJ-Adv_FLUXNET2015_SUBSET_DD_2011-2014_1-4.csv') as csv:
lines = csv.readlines()
for i in range(2, len(lines)):
tmp=lines[i].split(",")
XNR.append(float(i))
Xdt.append(float(tmp[0]))
YGP.append(float(tmp[312]))
YPP.append(float(tmp[54]))
I'm trying to create chart just like in seaborn documentation that looks like this:
on my dataframe with the following script:
import pandas as pd
import numpy as np
import pickle
import seaborn as sns
g = sns.PairGrid(df_num, hue="NDVI")
g.map_diag(sns.histplot, hue=None, color=".3")
g.map_offdiag(sns.scatterplot)
g.add_legend()
but I get the error message:
AttributeError: module 'seaborn' has no attribute 'histplot'
I have seen this post regard teh same issue but I couldn't solve it on my notebook. I'm working with jupyterlab notebookk on a server, I haven't reassigned "sns" before to any other variable, I think I have the most updated version (I have install the package again using pip install).
My qeustion is what else can throw this error? what am I missing? is there any way to bypass it?
I am running Python 2.7.10 on a Macbook.
I have installed:
Homebrew
Python 2.x, 3.x
NI-VISA
pip
pyvisa, pyserial, numpy
PyVISA
Anaconda
Pandas
I am attempting to run this script. A portion of it can be read here:
import visa
import time
import panda
import sys
import os
import numpy
os.system('cls' if os.name == 'nt' else 'clear') #clear screen
rm = visa.ResourceManager()
rm.list_resources()
print(rm.list_resources())
results = panda.DataFrame(columns=['CURR', 'VOLT', 'TIME'])
This is what is returned on the command line, below.
Note the line that says
AttributeError: 'module' object has no attribute 'DataFrame'
(u'USB0::0x05E6::0x2280::4068201::INSTR', u'ASRL1::INSTR', u'ASRL2::INSTR', u'ASRL4::INSTR')
Traceback (most recent call last):
File "k2280.py", line 14, in <module>
results = panda.DataFrame(columns=['CURR', 'VOLT', 'TIME'])
AttributeError: 'module' object has no attribute 'DataFrame'
Any help or insight on this issue would be appreciated.
It's pandas, not panda, so use import pandas instead. It's also common practice to import pandas as pd for convenience:
import pandas as pd
df = pd.DataFrame()
The module is called pandas not panda
python3 -m pip install pandas
import pandas as pd
pd.DataFrame()
Please read if you're new to python.
As I am also new to python since 2 days and going through the tutorial.
What I know is pandas are the packages we install in the python library to the machine we are using.
As I am new and I was practicing to import and use pandas.DataFrame I kept my filename as pandas.py
And here is the error I was doing. I can't use pandas.py because the machine is assuming its module inside this pandas.py
I changed the filename and it start working fine.
Few things to know if you're getting errors.
You are using pandas.py as filename, you need to change the file name
You are not importing pandas in the file and started working on its module
You are not using DataFrame in camel case
I think these 3 things should be kept in mind to use DataFrame to avoid this error.
I'm trying to import pandas as pd. I get ModuleNotFoundError: No module named 'pandas.rpy'. Why? I use pandas 0.20.1 + python 3.6 x64 + Windows 7 .
Example:
import os
os.environ['R_HOME'] = 'C:\Program Files\R\R-3.4.0'
os.environ['R_USER'] = 'bob'
import rpy2.robjects as robjects
import pandas.rpy.common as com
import pandas as pd
Returns:
Traceback (most recent call last):
File "C:\doc\GitHub\proj\src\open_rdata.py", line 19, in <module>
import pandas.rpy.common as com
ModuleNotFoundError: No module named 'pandas.rpy'
pandas.rpy module was deprecated and later removed. It does not exist in the version you are currently using.
You can either downgrade your pandas version, or better yet, have a look at the new rpy2 project.
From pandas documentation:
Up to pandas 0.19, a pandas.rpy module existed with functionality to
convert between pandas and rpy2 objects. This functionality now lives
in the rpy2 project itself. See the updating section of the previous
documentation for a guide to port your code from the removed
pandas.rpy to rpy2 functions.
You can see the rpy2 documentation here, and panda's reference for it here.
edit: per Analytical Monk's comment, corrected the phrasing to refer rpy2 as a different library, and not a part of pandas