Warum erhalte ich 5 Spalten, wenn ich 3-Spal-Datenrahmen kombiniere?Python

Python-Programme
Anonymous
 Warum erhalte ich 5 Spalten, wenn ich 3-Spal-Datenrahmen kombiniere?

Post by Anonymous »

Excel -Datei Nr. 1: < /p>

Code: Select all

Date      Data1   Data2
1-1-2025   x1       x2
1-2-2025   x3       x4
< /code>
Excel -Datei #2: < /p>
Date      Data1   Data2
1-3-2025   y1       y2
1-4-2025   y3       y4
< /code>
Ich möchte sie in eine einzelne Datei zusammenführen: < /p>
Date      Data1   Data2
1-1-2025   x1       x2
1-2-2025   x3       x4
1-3-2025   y1       y2
1-4-2025   y3       y4
< /code>
Mein Code: < /p>
for file_path in file_paths:
# Get the date from the file name
file_name = file_path
file_name = os.path.splitext(file_name)[0]
file_name = file_name[-8:]
file_name = file_name.replace('_','/')
# Read the Excel file
df = pd.read_excel(file_path, sheet_name='Parte', usecols='O:AN', skiprows=10, nrows=110, header=[0])
data_frames.append(df)
combined_df = pd.concat(data_frames, ignore_index=True)
combined_df.to_excel('rute1', index=False)
< /code>
Das Ergebnis ist nicht korrekt: < /p>
Date      Data1   Data2
1-1-2025   x1       x2
1-2-2025   x3       x4
1-3-2025                          y1       y2
1-4-2025                          y3       y4

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post