Skip to content

Instantly share code, notes, and snippets.

@montj2
Created June 15, 2023 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save montj2/71509fc839ceb6cf2b4f2547369e5da0 to your computer and use it in GitHub Desktop.
Save montj2/71509fc839ceb6cf2b4f2547369e5da0 to your computer and use it in GitHub Desktop.
Pandas sample
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