ExcelWriter belongs to the pandas module, not to a DataFrame instance.

writer = dfs2.ExcelWriter should be writer = pd.ExcelWriter

Answer from DeepSpace on Stack Overflow
🌐
Pandas
pandas.pydata.org › pandas-docs › version › 0.22 › generated › pandas.DataFrame.to_excel.html
pandas.DataFrame.to_excel — pandas 0.22.0 documentation
DataFrame.to_excel(excel_writer, sheet_name='Sheet1', na_rep='', float_format=None, columns=None, header=True, index=True, index_label=None, startrow=0, startcol=0, engine=None, merge_cells=True, encoding=None, inf_rep='inf', verbose=True, freeze_panes=None)[source]¶ ... If passing an existing ExcelWriter object, then the sheet will be added to the existing workbook.
Discussions

Cannot Export to Excel
Hey Henry, I'm experiencing the following error: AttributeError: 'PrettyPandas' object has no attribute 'to_excel' I also tried to shove the results in a list, and spit the list back out as a dataframe, but that totally failed as well. W... More on github.com
🌐 github.com
7
May 22, 2018
python - Pandas export to_excel error: 'DataFrame' object has no attribute 'data' - Stack Overflow
I use the following code to try and make a dataframe from a Tf-Idf vectorizer. The output of the vectorizer's fit_transform is a sparse matrix so I use toarray() to convert to array, and then pandas. More on stackoverflow.com
🌐 stackoverflow.com
March 24, 2019
AttributeError: module 'pandas' has no attribute 'read_excel'
Probably a file called 'pandas.py' in your project folder. It will get imported first as that way you can overrule imports from the central library, but as you then have no 'read_excel' defined it will fail on that step. Groetjes More on reddit.com
🌐 r/learnpython
6
1
December 7, 2023
BUG: writing dataframe to excel if one of the rows has name "render" fails
I try to write an dataframe to excel with excel. It fails if a row is called "render". Pandas version 1.0.3 Reproduce with: s1 = pandas.Series(("1","2"),index=["a... More on github.com
🌐 github.com
2
May 23, 2020
🌐
freeCodeCamp
forum.freecodecamp.org › python
Df.to_excel('fsl16days') - Python
August 20, 2020 - Hi , Am a beginner in python , you could consider this as my 1st project. So at work we consolidate excel sheets a lot , and as a temp i would be tasked to it always! Copying and pasting over and over again got to me…
🌐
GitHub
github.com › HHammond › PrettyPandas › issues › 49
Cannot Export to Excel · Issue #49 · HHammond/PrettyPandas
May 22, 2018 - Hey Henry, I'm experiencing the following error: AttributeError: 'PrettyPandas' object has no attribute 'to_excel' I also tried to shove the results in a list, and spit the list back out as a dataframe, but that totally failed as well. W...
Published   May 22, 2018
Author   apkant0neze
🌐
Reddit
reddit.com › r/learnpython › attributeerror: module 'pandas' has no attribute 'read_excel'
r/learnpython on Reddit: AttributeError: module 'pandas' has no attribute 'read_excel'
December 7, 2023 -

Hi!

Since a few weeks I have been trying out Python.

Currently I am struggling with reading an Excel-file with Python.

I use PyCharm.

Below is the error i get when. Someone has experience with this?

Traceback (most recent call last):

File "C:\Users\myname\PycharmProjects\pythonProject11\oefenen.py", line 2, in <module>

df = pd.read_excel('test.xlsx')

AttributeError: module 'pandas' has no attribute 'read_excel'

Process finished with exit code 1

🌐
GitHub
github.com › pandas-dev › pandas › issues › 34331
BUG: writing dataframe to excel if one of the rows has name "render" fails · Issue #34331 · pandas-dev/pandas
May 23, 2020 - I try to write an dataframe to excel with excel. It fails if a row is called "render". Pandas version 1.0.3 Reproduce with: s1 = pandas.Series(("1","2"),index=["a","b"]) s2 = pandas.Series(("3","4"),index=["b","b"]) df = pandas.DataFrame...
Published   May 23, 2020
Author   dwintergruen
Find elsewhere
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.ExcelWriter.html
pandas.ExcelWriter — pandas 3.0.2 documentation - PyData |
df.to_excel(writer) ... >>> df1 = pd.DataFrame([["AAA", "BBB"]], columns=["Spam", "Egg"]) >>> df2 = pd.DataFrame([["ABC", "XYZ"]], columns=["Foo", "Bar"]) >>> with pd.ExcelWriter("path_to_file.xlsx") as writer: ... df1.to_excel(writer, sheet_name="Sheet1") ...
🌐
Python Forum
python-forum.io › thread-11795.html
Pandas - Write to Exisitng Excel File - Sorted List
hi friends how can i write my sorted list to an exisitng excel file ie sheet name and column number from openpyxl import load_workbook import pandas as pd from pandas import ExcelWriter from pandas import ExcelFile df = pd.read_excel('python.xl...
🌐
Stack Overflow
stackoverflow.com › questions › 56222403 › pandas-function-object-has-no-attribute-to-excel
python - Pandas 'function' object has no attribute 'to_excel' - Stack Overflow
The function drop_duplicates does not have an extension function called to_excel, so the error is correct. ... you will see that your code runs. This is because df.drop_duplicates() returns a DataFrame, and a DataFrame has the to_excel() function.
🌐
Itsourcecode
itsourcecode.com › home › attributeerror: ‘dataframe’ object has no attribute ‘write’ [solved]
Attributeerror: 'dataframe' object has no attribute 'write' [SOLVED]
April 14, 2023 - In this code, the “to_csv” ... the “index=False” parameter. ... The other way to fix the error is by using the “to_excel” method....
Top answer
1 of 5
2

"sklearn.datasets" is a scikit package, where it contains a method load_iris().

load_iris(), by default return an object which holds data, target and other members in it. In order to get actual values you have to read the data and target content itself.

Whereas 'iris.csv', holds feature and target together.

FYI: If you set return_X_y as True in load_iris(), then you will directly get features and target.

from sklearn import datasets
data,target = datasets.load_iris(return_X_y=True)
2 of 5
1

The Iris Dataset from Sklearn is in Sklearn's Bunch format:

print(type(iris))
print(iris.keys())

output:

<class 'sklearn.utils.Bunch'>
dict_keys(['data', 'target', 'target_names', 'DESCR', 'feature_names', 'filename'])

So, that's why you can access it as:

x=iris.data
y=iris.target

But when you read the CSV file as DataFrame as mentioned by you:

iris = pd.read_csv('iris.csv',header=None).iloc[:,2:4]
iris.head()

output is:

    2   3
0   petal_length    petal_width
1   1.4 0.2
2   1.4 0.2
3   1.3 0.2
4   1.5 0.2

Here the column names are '1' and '2'.

First of all you should read the CSV file as:

df = pd.read_csv('iris.csv')

you should not include header=None as your csv file includes the column names i.e. the headers.

So, now what you can do is something like this:

X = df.iloc[:, [2, 3]] # Will give you columns 2 and 3 i.e 'petal_length' and 'petal_width'
y = df.iloc[:, 4] # Label column i.e 'species'

or if you want to use the column names then:

X = df[['petal_length', 'petal_width']]
y = df.iloc['species']

Also, if you want to convert labels from string to numerical format use sklearn LabelEncoder

from sklearn import preprocessing
le = preprocessing.LabelEncoder()
y = le.fit_transform(y)
🌐
Quora
quora.com › How-do-you-fix-pandas-that-have-no-attribute-dataframe
How to fix pandas that have no attribute dataframe - Quora
Answer (1 of 2): There are three possibilities here : * The filename could be pandas.py * The filename could be whatever you have imported as, for example, pd. You could have imported using import pandas as pd * There is another file with the name pandas.py or pd.py in the current directory W...