Home > Enterprise >  Delete the Column, created with merge dataframes
Delete the Column, created with merge dataframes

Time:11-04

With this code, I merge 3 files together:

import pandas as pd
import openpyxl as op
from openpyxl import load_workbook
from openpyxl import Workbook
import numpy as np
path = r"users.xlsx"
data = pd.read_excel(path, engine='openpyxl')
df = pd.DataFrame(data)
NumberOfChild = df.groupby('Parent ID')['Parent ID'].count().to_frame('Employees Number')
NC = pd.DataFrame(NumberOfChild)
NumberOfBooking = df.groupby('Parent ID')['Reservations Count'].sum().to_frame('Total employees bookings')
NB = pd.DataFrame(NumberOfBooking)
result = df.merge(NC, left_on=['ID'], right_on=['Parent ID'], how='left').merge(NB, left_on=['ID'], right_on=['Parent ID'], how='left')
result.drop(result.columns[0], axis=1)
with pd.ExcelWriter('NC_Merge.xlsx') as writer:
    result.to_excel(writer, sheet_name='WorkSheet')

After Merge, an additional column is added to the table at the beginning. I tried to delete it with this command but could not.

result.drop(result.columns[0], axis=1)

Is there an idea? somthing like first column of the photo

CodePudding user response:

I believe what you are asking about is the index that was assigned to your new dataframe. You can look at this answer to a similar question:

  • Related