Transposing CSV Data (Rotate Rows to Columns)
How to transpose CSV files—swapping rows and columns. Use Excel Paste Special, Python Pandas, or online tools to reshape your data.
Transposing CSV Data (Rotate Rows to Columns)
Sometimes your data is "wide" when it needs to be "tall", or vice versa.
Original (Wide):
Name,Jan,Feb,Mar
Sales,100,200,150
Costs,50,60,55
Transposed (Tall):
Name,Sales,Costs
Jan,100,50
Feb,200,60
Mar,150,55
This operation is called Transposing.
Method 1: Excel "Paste Special"
- Open CSV in Excel.
- Select all data (Ctrl+A).
- Copy (Ctrl+C).
- Click on an empty cell (or new sheet).
- Right-click > Paste Special.
- Check the Transpose box (bottom right).
- Click OK.
Pros: Visual, easy. Cons: Manual; limited by Excel's row/column limits.
Method 2: Python (Pandas)
One line of code.
import pandas as pd
df = pd.read_csv('data.csv', header=None) # header=None if you want to rotate headers too
df_transposed = df.T
df_transposed.to_csv('transposed.csv', header=False, index=False)
Method 3: Online Tool
If you don't have Excel or Python handy.
When to Transpose?
- Charting: Chart tools often expect time series in rows, not columns.
- Database Import: Databases prefer "Tall" data (normalized) over "Wide" matrices.
- Comparison: It's often easier to compare metrics side-by-side (columns) than row-by-row.
Warning: Header Confusion
When you transpose, your Headers become the first Column. And your first Column becomes the Headers.
Ensure your data makes sense after rotation. You might need to rename the new header row manually.
Need to rotate data? HappyCSV can transpose your CSV file in seconds directly in the browser.
Related Articles
Convert CSV to HTML Table
Convert CSV files to HTML table code for websites. Free online tool with proper escaping and semantic markup.
Convert CSV to Markdown Table
Convert CSV files to Markdown tables for GitHub README files, documentation, and blog posts. Free online tool.
Convert TSV to CSV (Tab-Separated to Comma-Separated)
Convert TSV files to standard CSV format. Free online converter for tab-delimited data. Works with Excel exports.
Need to handle CSV files?
HappyCSV is the free, secure way to merge, split, and clean your data — all in your browser.