1. 读取csv文件
in_out_data = pd.read_csv(filename,usecols=[0,1,2,3],decimal='.',header=None,\
names=['id','date','tBalance','yBlacne',],skiprows=1)
- usecols: 指定要读取的列
- header : CSV文件的列名所在的行, int, list of ints. Row number(s) to use as the column names, and the start of the data. Defaults to 0 if no names passed, otherwise None.
- index_col : 指定行标签所在的列,int or sequence or False, default None. Column to use as the row labels of the DataFrame.
- names : 列的名称,array-like. List of column names to use.
- skiprows=n: 要跳过的前n行
2. 保存为csv文件
df.to_csv('predict_result1.csv',columns=[0,1,2],header=False,index=False)
- columns : 指定需要存储的列,Columns to write
- header : 是否把列的名字写入CSV文件, boolean, default True. Write out column names. If a list of string is given it is assumed to be aliases for the column names
- index : 是否把index写入CSV文件,boolean, default True.Write row labels (index)
- index_label : 如果将index写入CSV文件,那么给出index列的标签(列的名字),string or sequence, or False, default None.
网友评论