Trying to use different sized headers for malformed csv #402
-
Hi everyone, I've worked on this for a few hours now and I can't seem to get this csv parsed. This is my data first off (I know its very malformed).
The problem is that the headers are 4 columns long and the data is 6 columns long. I've tried to get around this with some of the advanced options csv has for the reader. fn eye_gazes(path: &PathBuf, wait: Wait) -> Vec<EyeGaze> {
let csv_path = path
.join(format!("{}{}", EYEGAZE_BASENAME, wait.to_string()))
.with_extension(DATA_FILE_EXTENSION);
let file = File::open(csv_path).expect("Unable to open file.");
let custom_headers = vec!["delta", "unity_time", "game_object", "x", "y", "z"];
let mut rdr = ReaderBuilder::new().has_headers(false).from_reader(file);
dbg!("headers {}", &rdr.headers());
rdr.set_headers(custom_headers.into());
dbg!("headers {}", &rdr.headers());
let mut iter = rdr.records();
// let _headers = iter.next();
let records: Vec<_> = iter.collect();
dbg!("row 0 {}", &records[0]);
dbg!("row 1 {}", &records[1]);
todo!();
} With this exact version of the code I get this output
Honestly this might actually be a bug, because the library doesn't update the expected length when the header size changes. But any help is welcomed 🙏 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Enable the flexible option. Otherwise the csv reader will error when it finds records of unequal length. It doesn't matter if you set the headers to something different or not. |
Beta Was this translation helpful? Give feedback.
Enable the flexible option. Otherwise the csv reader will error when it finds records of unequal length. It doesn't matter if you set the headers to something different or not.