Python Forum
Pandas AttributeError: 'DataFrame' object has no attribute 'concat'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pandas AttributeError: 'DataFrame' object has no attribute 'concat'
#1
Dears

I am trying to merge multiple excel files into a single file with Python, but I get an error and I can't fix it.


My Code is
import os
import pandas as pd
cwd = os.path.abspath('') 
files = os.listdir(cwd)  
folder = r"C:\Users\Sameer\Downloads\Sales"

## Method 1 gets the first sheet of a given file
df = pd.DataFrame()
for file in files:
    if file.endswith('.xlsx'):
        df = df.append(pd.read_excel(file), ignore_index=True) 
df.head() 
df.to_excel('total_sales.xlsx')



## Method 2 gets all sheets of a given file
df_total = pd.DataFrame()
for file in files:                         # loop through Excel files
    if file.endswith('.xlsx'):
        excel_file = pd.ExcelFile(file)
        sheets = excel_file.sheet_names
        for sheet in sheets:               # loop through sheets inside an Excel file
            df = excel_file.parse(sheet_name = sheet)
            df_total = df_total.append(df)
df_total.to_excel('combined_file.xlsx')
Error:
C:\Users\Sameer\PycharmProjects\merage\venv\Scripts\python.exe C:\Users\Sameer\PycharmProjects\merage\main.py C:\Users\Sameer\PycharmProjects\merage\main.py:11: FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead. df = df.append(pd.read_excel(file), ignore_index=True) C:\Users\Sameer\PycharmProjects\merage\main.py:11: FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead. df = df.append(pd.read_excel(file), ignore_index=True) Traceback (most recent call last): File "C:\Users\Sameer\PycharmProjects\merage\main.py", line 24, in <module> df_total = df_total.concat(df) ^^^^^^^^^^^^^^^ File "C:\Users\Sameer\PycharmProjects\merage\venv\Lib\site-packages\pandas\core\generic.py", line 5902, in __getattr__ return object.__getattribute__(self, name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'DataFrame' object has no attribute 'concat'
Yoriz write Feb-17-2023, 03:24 PM:
Please post all code, output and errors (in their entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.

Attached Files

.xlsx   Sales1.xlsx (Size: 13.14 KB / Downloads: 114)
.xlsx   Sales2.xlsx (Size: 13.25 KB / Downloads: 115)
Reply


Messages In This Thread
Pandas AttributeError: 'DataFrame' object has no attribute 'concat' - by Sameer33 - Feb-17-2023, 02:05 PM
RE: I need help !!!! - by Yoriz - Feb-17-2023, 03:35 PM
RE: I need help !!!! - by deanhystad - Feb-17-2023, 04:15 PM
RE: I need help !!!! - by Sameer33 - Feb-17-2023, 04:32 PM
RE: I need help !!!! - by deanhystad - Feb-17-2023, 04:53 PM
RE: I need help !!!! - by Sameer33 - Feb-17-2023, 06:01 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Alteryx QS-Passing pandas dataframe column inside SQL query where condition sanky1990 0 767 Dec-04-2023, 09:48 PM
Last Post: sanky1990
  getpass.getpass() results in AttributeError: module 'os' has no attribute 'O_NOCTTY' EarthAndMoon 4 804 Oct-03-2023, 02:00 PM
Last Post: deanhystad
  AttributeError: '_tkinter.tkapp' object has no attribute 'username' Konstantin23 4 1,799 Aug-04-2023, 12:41 PM
Last Post: Konstantin23
  DataFRame.concat() nafshar 3 810 Jul-14-2023, 04:41 PM
Last Post: nafshar
  Question on pandas.dataframe merging two colums shomikc 4 869 Jun-29-2023, 11:30 AM
Last Post: snippsat
  Python: Regex is not good for re.search (AttributeError: 'NoneType' object has no att Melcu54 9 1,563 Jun-28-2023, 11:13 AM
Last Post: Melcu54
  Parallel processing - AttributeError: Can't get attribute 'sktimekmeans' Mohana1983 1 785 Jun-22-2023, 02:33 AM
Last Post: woooee
  Python: AttributeError: 'PageObject' object has no attribute 'extract_images' Melcu54 2 3,988 Jun-18-2023, 07:47 PM
Last Post: Melcu54
  Object attribute behavior different in 2 scripts db042190 1 773 Jun-14-2023, 12:37 PM
Last Post: deanhystad
  cx_oracle Error - AttributeError: 'function' object has no attribute 'cursor' birajdarmm 1 2,443 Apr-15-2023, 05:17 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020