xxxxxxxxxx
import pandas as pd
# Read the Excel file into a DataFrame
excel_file = pd.read_excel("your_file.xlsx")
# Specify the row to transpose (e.g., row 1)
row_to_transpose = excel_file.iloc[0]
# Transpose the row into a column
transposed_column = row_to_transpose.transpose()
# Write the transposed data to a new column in the DataFrame
excel_file['Transposed Column'] = transposed_column
# Save the modified DataFrame to a new Excel file
excel_file.to_excel("output_file.xlsx", index=False)
xxxxxxxxxx
This webpage may help you:
https://support.microsoft.com/en-us/office/transpose-rotate-data-from-rows-to-columns-or-vice-versa-3419f2e3-beab-4318-aae5-d0f862209744
It explains how to transpose or rotate data from rows to colums or vice versa.
xxxxxxxxxx
import openpyxl
# Load the Excel workbook
workbook = openpyxl.load_workbook('your_file.xlsx')
# Select the sheet name where the data resides
sheet = workbook['Sheet1'] # Replace 'Sheet1' with the actual sheet name
# Get the values from the column
column_values = []
for cell in sheet['A']:
column_values.append(cell.value)
# Transpose the column values to a row
row_values = [column_values]
# Clear the existing data in the sheet
sheet.delete_rows(1, sheet.max_row)
# Write the transposed row into the sheet
for index, row_value in enumerate(row_values, start=1):
sheet.append(row_value)
# Save the modified workbook
workbook.save('modified_file.xlsx')
xxxxxxxxxx
In excel
Right-click over the top-left cell of where you want to paste the transposed table, then choose Transpose