Pandas transpose one column:
To transpose one column in pandas, you can use the
transpose()
function.
Here’s an example:
import pandas as pd # Create a DataFrame df = pd.DataFrame({'Names':['John', 'Sam', 'Alice'], 'Ages':[25, 28, 30]}) # Transpose the 'Names' column transposed_df = df['Names'].transpose() print(transposed_df)
This will output:
0 John 1 Sam 2 Alice Name: Names, dtype: object
In this example, we created a DataFrame with two columns: ‘Names’ and ‘Ages’. We then used the transpose()
function to transpose the ‘Names’ column, resulting in a Series with the transposed values.
- Protoc did not exit cleanly. review output for more information
- Python cannot mask with non-boolean array containing na / nan values
- Pandas to_html border style
- Property ‘children’ does not exist on type ‘reactnode’
- Pyodbc drivers empty
- Property ‘spring.profiles.active’ imported from location ‘class path resource [application-test.yml]’ is invalid in a profile specific resource
- Python selenium send keys without element
- Pandas excel file format cannot be determined, you must specify an engine manually.
- Property ‘div’ does not exist on type ‘jsx.intrinsicelements’
- Pandas to_sql update if exists