If column B is the same, it will be displayed in column C. Didn’t you understand? The standard library has cvs support, wouldn’t it be enough to parse and convert it into python data type?
The requirements are not very clear. Looking at your picture, if the data in columns A and B are sorted, and there are at most two identical data in column B, then sort out your requirements first
The original data is in columns A and B, both of which are integers. Column B is arranged from small to large. If column B is the same, column A is also arranged from small to large. If the values in column B are the same, the corresponding values in column A are Subtract the values and insert the result into column C
First of all, the CSV file can be read line by line. The intervals between different cells in the same line are ,, 行尾有n表示结束. 所以思路是按行读取, 存成一个二元列表, 依次比较, 比较完成后再用join插入, and n and it can be stored in the csv file. The code is as follows:
my_list = [[80, 7], [153, 7], [188, 19], [80, 20]]
for i in range(1,len(my_list)):
if my_list[i-1][1] == my_list[i][1]:
my_list[i].append(my_list[i][0] - my_list[i-1][0])
print my_list
# [[80, 7], [153, 7, 73], [188, 19], [80, 20]]
If column B is the same, it will be displayed in column C. Didn’t you understand? The standard library has cvs support, wouldn’t it be enough to parse and convert it into python data type?
The requirements are not very clear. Looking at your picture, if the data in columns A and B are sorted, and there are at most two identical data in column B, then sort out your requirements first
The original data is in columns A and B, both of which are integers. Column B is arranged from small to large. If column B is the same, column A is also arranged from small to large. If the values in column B are the same, the corresponding values in column A are Subtract the values and insert the result into column C
First of all, the CSV file can be read line by line. The intervals between different cells in the same line are
,
, 行尾有n表示结束. 所以思路是按行读取, 存成一个二元列表, 依次比较, 比较完成后再用join插入,
and n and it can be stored in the csv file. The code is as follows: