Search Results

    Swap Columns

    Switch column order in CSV or tabular data

    1


    Share

    What Is the Swap Columns Tool?

    The Swap Columns tool exchanges the positions of two columns in CSV or delimited tabular data across every row at once. You specify which two column positions to swap, set the delimiter that separates your fields, click the button, and the tool rearranges those columns throughout the entire dataset. It is useful when data arrives in the wrong column order and you need to reposition fields before importing, processing, or sharing it.

    Doing a column swap manually in a large CSV is the kind of task that sounds quick and then quietly consumes fifteen minutes. This tool handles the whole thing in one step.

    How to Use This Tool

    1. Paste or type your CSV or tabular data into the input box above.
    2. Enter the position of the first column to swap in the Column 1 field and the position of the second column in the Column 2 field. Columns are numbered from 1, so the first column is 1, the second is 2, and so on. Set the Delimiter to match your data, comma for CSV, tab for TSV, pipe for pipe-delimited, and so on.
    3. Click Swap Columns and the tool exchanges those two columns across every row in your input.
    4. Copy the result using the Copy button, or select and copy manually. Use Clear to reset the input.

    When Would You Use This?

    Reordering columns in a CSV export where the field order does not match what your import template expects, without opening the file in a spreadsheet application and moving columns around manually.

    Fixing data that arrived with two fields in the wrong positions, such as a first name and last name that got reversed in the export, by swapping them back across every row in one operation.

    Quickly repositioning columns in copied tabular data before passing it to another tool, a database, or a script that expects fields in a specific order and will misread the content if they are in the wrong positions.

    Examples

    Swapping columns 1 and 2 in CSV data

    Input   : Alice,alice@email.com,London
    Bob,bob@email.com,Paris
    Carol,carol@email.com,Berlin

    Column 1: 1

    Column 2: 2

    Delimiter: , (comma)

    Output  : alice@email.com,Alice,London
    bob@email.com,Bob,Paris
    carol@email.com,Carol,Berlin

    Swapping non-adjacent columns

    Input   : 101,Product A,9.99,In Stock
    102,Product B,14.99,Out of Stock

    Column 1: 1

    Column 2: 3

    Delimiter: , (comma)

    Output  : 9.99,Product A,101,In Stock
    14.99,Product B,102,Out of Stock

    Swapping columns in pipe-delimited data

    Input   : Alice|Manager|London
    Bob|Developer|Paris

    Column 1: 2

    Column 2: 3

    Delimiter: | (pipe)

    Output  : Alice|London|Manager
    Bob|Paris|Developer

    Frequently Asked Questions

    How do I swap columns in a CSV file?

    Paste your CSV data into the input box, enter the two column numbers you want to exchange, set the delimiter to a comma, and click Swap Columns. The two columns switch positions across every row.

    How do I swap columns in Excel?

    Select the column you want to move, hold Shift, and drag it to the new position. Or cut the column, insert a blank column where you want it, and paste. For plain-text CSV data outside of Excel, this tool is faster and does not require opening the file.

    How do I swap columns in Python?

    For a CSV loaded into a list of lists, swap the values at the two column indices for each row: for row in data: row[0], row[1] = row[1], row[0]. For a pandas DataFrame: df[['col_a', 'col_b']] = df[['col_b', 'col_a']]. For a quick manual swap without code, use this tool.

    What does column number 1 mean?

    Column 1 is the first field in each row, counting from the left. Column 2 is the second field, and so on. Columns are numbered starting at 1, not 0.

    Can I swap non-adjacent columns?

    Yes. The tool swaps whatever two column positions you specify, whether they are next to each other or several columns apart. Just enter the correct position numbers for both.

    What delimiter should I use?

    Match it to your data. CSV files use a comma, TSV files use a tab, some exports use a pipe or semicolon. Look at one row of your data to confirm which character separates the fields.

    What if my data has a header row?

    The tool typically processes all rows including the header, so the header columns will also be swapped along with the data rows. That is usually what you want, since the header label should follow the data it describes.

    Can I swap more than two columns at once?

    This tool swaps two specified columns per operation. For more complex reordering, run the swap multiple times using the output of each step as the input for the next.

    Does it work with tab-separated data?

    Yes. Set the delimiter to a tab character and the tool handles TSV files the same way it handles CSV.