我正在尝试重新学习 rust 中的数据科学。
我有一个Vec<String>
包含分隔符“|” 和一个新行“!结束”。
我想结束的是Vec<Vec<String>>
可以放入 2D ND 阵列。
我有这个python代码:
file = open('somefile.dat')
lst = []
for line in file:
lst += [line.split('|')]
df = pd.DataFrame(lst)
SAMV2FinalDataFrame = pd.DataFrame(lst,columns=column_names)
我在这里用 rust 重新创建了它:
fn lines_from_file(filename: impl AsRef<Path>) -> Vec<String> {
let file = File::open(filename).expect("no such file");
let buf = BufReader::new(file);
buf.lines()
.map(|l| l.expect("Could not parse line"))
.collect()
}
fn main() {
let lines = lines_from_file(".dat");
let mut new_arr = vec![];
//Here i get a lines immitable borrow
for line in lines{
new_arr.push([*line.split("!end")]);
}
// here i get expeected closure found str
let x = lines.split("!end");
let array = Array::from(lines)
我有什么:['1','1','1','end!','2','2','2','!end'] 我需要什么:[['1',' 1','1'],['2','2','2']]
编辑:还有为什么当我涡轮鱼时它会在 Stack Overflow 上消失?