8. Reshape

Reshape the Data into Long or Wide Format

  1. Choose the Reshape under the Data Analysis category.

  1. Select the Reshape type.

2-1. Pivot: Reshape the data into a wide data format.

2-2. Pivot Table: Reshape the data into a wide format and apply aggregation functions if duplicate indices or columns exist.

2-3. ape the data into a long data format.


Pivot & Pivot Table

  1. Select the DataFrame to be reshaped into wide data.

  2. Choose the column to be set as the index in the reshaped DataFrame.

  3. Select the column to be set as the columns in the reshaped DataFrame.

  4. Choose the column to fill the values in each column of the reshaped DataFrame.

  5. [Pivot Table] Select which aggregation function to apply for duplicate indices or columns. If multiple aggregation functions are selected, the results of each function are individually generated. For example, applying Count and First aggregation functions to columns A, B, and C would create six columns.

  6. Additional code beyond the functionalities provided by Visual Python can be added.

  7. Specify the variable name to assign to the result.

  8. Reset the index to assign a new default integer index.

  9. Preview the code that will be output in Code View.

  10. Preview the resulting DataFrame in Data View.

  11. Execute the code.


Melt

  1. Select the DataFrame to be reshaped into long data.

  2. Choose the column(s) to be specified as fixed variables in the reshaped DataFrame. These columns will be retained as they are in the reshaped DataFrame.

  3. The names of the selected column(s) will be filled in the 'A' column of the reshaped DataFrame, and the corresponding values from the original DataFrame will be filled in the 'B' column.

  4. Optionally provide additional desired options.

  5. Specify the variable name to assign to the result.

  6. Reset the index to assign a new default integer index.

  7. Preview the code that will be output in Code View.

  8. Preview the resulting DataFrame in Data View.

  9. Execute the code.

Last updated