Rearrange a CSV file

조회 수: 14 (최근 30일)
Frank Lindsey
Frank Lindsey 2021년 5월 24일
편집: Monika Jaskolka 2021년 5월 30일
Hello to whomever
i need to extract a specific data (columns) from a csv file and transfer to another file columns. without copying and paste
My csv file contains 20 columns with over 7000 rows, i want to extract the X colum from file abc and move it to column F in file test1.
Rearrange example: current file has ID in column H but the correct format column the ID section is in C
I am trying to think of a way for me to write code that will allow me to move columns and then grab/get rows to group them. or is there away in excel already?
Does this make sense?

답변 (1개)

Monika Jaskolka
Monika Jaskolka 2021년 5월 30일
편집: Monika Jaskolka 2021년 5월 30일
Assuming your data has headers to identify the column names as A...X:
t1 = readtable('abc.csv');
t2 = readtable('test1.csv');
t2.F = t1.X;
If you don't want to overrwrite column F:
t1 = readtable('abc.csv');
t2 = readtable('test1.csv');
t2.newF = t1.X;
t2 = movevars(t2, 'newF', 'Before', 'F')

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by