I ran into the error:
" AttributeError: module 'pandas' has no attribute 'read_xml' "
This would be a huge lifesaver if I could ingest the XML with one function into a pandas df without trying to iterate through etc.
I am running pandas 1.3.4 and python 3.8.8. I have tried opening an xml in my local folder (where the script is housed).
I tried directly importing the file like so:
df = pd.read_xml('xmltest.xml')
As well as trying to import via a string like so:
txt = Path('xmltest.txt').read_text()
df = pd.read_xml(txt)
And both gave me the wrong error.. Any help would be awesome as this would be AMAZING to ingest XML with 1 function into a DF!!! Are there similar functions out there if this is no longer a valid solution?
It appears this person had the same problem but I'm currently running the updated pandas:
AttributeError: module 'pandas' has no attribute 'read_xml' or 'to_xml'
Related
I have written a lambda function for AWS which will use pandas for handling dataframe. When I tested this lambda function - I faced error - No module name pandas.
I further kept pandas and other dependencies libraries in library folder of my repository.
Now I am facing other issue which I am unable to solve.
Current error:
module 'pandas' has no attribute 'read_csv': AttributeError
Traceback (most recent call last):
File "/var/task/lambda_function.py", line 127, in lambda_handler
initial_df = pd.read_csv(obj['Body']) # 'Body' is a key word
AttributeError: module 'pandas' has no attribute 'read_csv'
I checked the solutions available on this site - like - module 'pandas' has no attribute 'read_csv
I don't have pandas.py and csv.py in my pandas folder but rather have test_to_csv.py, csvs.py and test_pandas.py, which is required as per the discussion in link provided above.
I am unable to figure out a way here.
Pandas is indeed not available by default on AWS lambda.
If you want to use Pandas with AWS lamdba, the easiest way is to use the AWS Data Wrangler layer.
When you add a new layer, select AWS layers , then in the dropdown menu you can select the AWSDataWrangler-Python39 one.
Once you have added the layer, you will be able to use pandas as usual.
using pandas in google colaboratory, I am attempting to import a .csv file named 'gifted.csv'. Using the following code:
df=pd.read_csv('/content/gifted.csv')
I have ran the pandas library as pd, but whenever I run the code, it does not function and the following error appears.
enter code hereTypeError: 'str' object is not callable
i dont know where the csv is located but try
df=pd.read_csv('content/gifted.csv')
without the '/' before the content
the error does not imply for it but try it.
more check about the import did the package installed well.
I am doing a data analysis project and while importing the csv file into spyder I am facing this error. Please help me to debug this as I am new to programming.
#import library
>>>import pandas as pd
#read the data from from csv as a pandas dataframe
>>>df = pd.read.csv('/Documents/Melbourne_housing_FULL.csv')
This is the error shown when I use the pd.read.csv command:
File "C:/Users/mylaptop/.spyder-py3/temp.py", line 4, in <module>
df = pd.read.csv('/Documents/Melbourne_housing_FULL.csv')
AttributeError: module 'pandas' has no attribute 'read'
you should use :
df = pd.read_csv('/Documents/Melbourne_housing_FULL.csv')
see here docs
you need to use pandas.read_csv() instead of pandas.read.csv() the error is litterally telling you this method doesn't exist .
I have 0.20.3 version of pandas install. I am trying to set header_style to false so that i can format the header row. xlsxwriter not applying format to header row of dataframe - Python Pandas
I keep getting error : AttributeError: 'module' object has no attribute 'formats'
I have tried
pd.formats.format.header_style = None
and
pd.core.format.header_style = None
Any idea what am I doing wrong ?
As you can see in the API, the module pandas.formats and pandas.core.format do not exist : https://pandas.pydata.org/pandas-docs/stable/api.html
It is normal that you have this error.
If you read new API changes with 0.20, pandas.formats has become pandas.io.formats. Try to check the API.
Another way to do this, suggested by #Martin Evans, is to write the headers directly, outside of Pandas. This avoids issues like above with different Pandas versions.
See also this example in the XlsxWriter docs.
I am trying to use pandas.read_excel but I keep getting " 'module' object has no attribute 'read_excel' " as an error in my terminal as shown
File "read.py", line 9, in <module>
cols = pd.read_excel('laucnty12', 'Poverty Data', index_col='State', \\ na_values=['NA'])
AttributeError: 'module' object has no attribute 'read_excel'
I have tried pd.read_excel() and pd.io.parsers.read_excel() but get the same error. I have python 2.7 installed and other parts of pandas work fine such as xls.parse and read_csv. My code is below:
import pandas as pd
from pandas import *
xls = pd.ExcelFile('laucnty12.xls')
data = xls.parse('laucnty12', index_col=None, na_values=['NA'])
cols = pd.read_excel('laucnty12', 'Poverty Data', index_col='State', na_values=['NA'])
print cols
df = pd.read_excel(filepath + 'Result.xlsx')
Check whether the extension of excel file is xls or xlsx then add the same in the query. I tried and its is working fine now.
You probably mean pd.io.excel.read_excel()
The problem is that your script is called "read.py". The Python file that defines read_excel already imports another module called "read" - so when you try and run your "read.py" script, it squashes the old "read" module that pandas is using, and thus breaks read_excel. This problem can happen with other "common" short names for scripts, like "email.py".
Try renaming your script.