Python实例:对表进行操作的代码示例
在Python中,可以使用以下代码对表进行操作:
import csv
file = r'd:/4.csv'
class CSV_Analyse:
def _read_csv(self, file):
reader = csv.reader(open(file, "rd"))
return [line for line in self.codes(reader)]
def codes(self, reader):
for line in reader:
yield [unicode(cell, 'gb18030') for cell in line]
def result_list(self, file):
pm_call = []
all_rows_no_title = self._read_csv(file)[1:] #如果不需要表头,可以用这行去掉; #[1:]指从1开始内容,而不是从默认的0开始
for line in all_rows_no_title:
if "1" in line[2]:
pm_call.append([line[3], line[4], line[5]])
else:
other_call.append([line[8], line[X]])
# 这是一个示例代码,用于演示如何使用Python对表进行操作。你可以根据自己的需求进行修改和调整。
下载地址
用户评论