Created
June 15, 2023 14:40
-
-
Save montj2/71509fc839ceb6cf2b4f2547369e5da0 to your computer and use it in GitHub Desktop.
Pandas sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
# Read the Excel spreadsheet into a pandas DataFrame | |
df = pd.read_excel('your_spreadsheet.xlsx') | |
# Specify the columns to keep intact | |
keep_columns = ['A', 'B', 'C'] | |
# Specify the columns to be transposed | |
transpose_columns = ['1', '2', '3', '4', '5'] | |
# Transpose the columns into rows | |
transposed_df = pd.melt(df, id_vars=keep_columns, value_vars=transpose_columns, var_name='Column', value_name='Value') | |
# Print the transposed DataFrame | |
print(transposed_df) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment