First, how to delete a column in the data
1) Open file Opening ()
2) for loop to read each line of the file
Strip ()--remove the leading and trailing spaces, split ()--splits the data with a space. Returns the list data
/**
This section operates on a data set
**/
3) Convert the list data to a string using the Join () function
4) Write data to file write ()
Example: Delete the column data of a file. The Python implementation code is as follows:
#-*-coding:utf-8-*-"""Created on Mon June 09:44:49 2015@author:chaofn"""defLoaddataset (fileName): Fr=Open (fileName) FP=open ('d:/01.test','W') """The type of curline adds a line break to the first column in the list removal data set to convert the type of listing to a string type""" forLineinchfr.readlines (): CurLine=line.strip (). Split (',') delCurline[0] Curline.append ('\ n') StrLine=','. Join (CurLine) fp.write (strLine) fp.close ()
Python Data set processing