
数据如下:
//file=date.txt 1::F::1::10::48067 2::M::56::16::70072 3::M::25::15::55117 4::M::45::7::02460 5::M::25::20::55455 比如我只想要提取前 3 列的内容,我的命令如下:
//file=volume.py import pandas as pd unames=['snapshot','volume','test'] id = pd.read_table("date.txt",sep="::",header=None,names=unames,engine='python') test=id pd.concat([test]).to_csv('volume.txt',sep=" ",index=False) 但是获得的是后 3 列的内容
//file=volue.txt snapshot volume test 1 10 48067 56 16 70072 25 15 55117 45 7 2460 25 20 55455 我想问的是如何提取前 3 列或者制定要哪几列作为内容吗?
1 raptium 2016 年 9 月 17 日 via Android 先全读进来,然后 df.iloc[:,[:3]] |
3 ruoyu0088 2016 年 9 月 17 日 有一个 usecols 参数,使用 usecols=[0, 1, 2]即可。 |