Need to get output in the following format using pandas

Need to get output in the following format using pandas

I have data in a pandas dataFrame which is as below

I have data in a pandas dataFrame which is as below

    Employee ID                        Employee Name  Day 1  Day 2       ...  Day 30  Day 31
0       1                              EMPLOYEE1       8.75   8.75       ...    8.75    8.75 
1       2                              EMPLOYEE2       0.00   8.00       ...    8.00    8.00

I need my output as follows:

1  Day 1  EMPLOYEE1 8.75
1  Day 2  EMPLOYEE1 8.75
.
.
1  Day 31 EMPLOYEE1 8.75
2  Day 1  EMPLOYEE2 0.00
2  Day 2  EMPLOYEE2 8.00
.
.
2  Day 31 EMPLOYEE2 8.00

This is the code

# Copy ID and Name to new dataFrame

df_EID = df[['Employee ID', 'Employee Name']].copy()

transpose the and copy the original dataframe to a new one

df_transpose = df.transpose()

make necessary changes to the transpose so that the column headers are the

Employee IDs and also delete the first index which has those IDs

df_transpose = df_transpose.rename(columns=df_transpose.iloc[0]) df_transpose.drop(df_transpose.index[0])

run Query to check just for the first employee

df_transpose[df_EID['Employee ID'][0:]]

#iterate

Expected Result

1  Day 1  EMPLOYEE1 8.75
1  Day 2  EMPLOYEE1 8.75
.
.
1  Day 31 EMPLOYEE1 8.75
2  Day 1  EMPLOYEE2 0.00
2  Day 2  EMPLOYEE2 8.00
.
.
2  Day 31 EMPLOYEE2 8.00
.
.

Actual Result

                           1       ...                     100
Employee ID                1       ...                     100
Employee Name      EMPLOYEE1       ...             EMPLOYEE100
Day 1                   8.75       ...                    8.75
.
.
.

Day 30 8.75 ... 8.75 Day 31 8.75 ... 8.75 Total Hours 188.25 ... 191.5

It seems I am actually going back to square one. Can you please help me on this? Can you also point out where I went wrong in my approach too? Thanks in advance. It would also be better if I put the output to another dataframe so I can write it to excel the same way as the expected output

python pandas

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Python Pandas Objects - Pandas Series and Pandas Dataframe

In this post, we will learn about pandas’ data structures/objects. Pandas provide two type of data structures:- ### Pandas Series Pandas Series is a one dimensional indexed data, which can hold datatypes like integer, string, boolean, float...

Basic Data Types in Python | Python Web Development For Beginners

In the programming world, Data types play an important role. Each Variable is stored in different data types and responsible for various functions. Python had two different objects, and They are mutable and immutable objects.

Python Pandas Tutorial - Data Analysis with Python Pandas

Python Pandas Tutorial - Data Analysis with Python Pandas will help you get started with Python Pandas Library for various applications including Data analysis. You'll learn: Introduction to Pandas; DataFrames and Series; How To View Data? Selecting Data; Handling Missing Data; Pandas Operations; Merge, Group, Reshape Data; Time Series And Categoricals; Plotting Using Pandas

PYTHON Pandas Basic Functions

PYTHON Pandas Basic Functions. So far, we have learned the three pandas data structure and how to create them. Due to its importance in real-time data processing, we will focus on dataframe objects right now and mention a few other data structures.

Python Pandas Tutorial - Data Analysis with Python Pandas

Python Pandas Tutorial will help you get started with Python Pandas Library for various applications including Data analysis. Introduction to Pandas. DataFrames and Series. How To View Data? Selecting Data. Handling Missing Data. Pandas Operations. Merge, Group, Reshape Data. Time Series And Categoricals. Plotting Using Pandas