python处理excel的问题
PHPz
PHPz 2017-04-17 17:30:10
0
5
378

对于一个这样的excel文件,

我现在想要做的是讲RevisionID相同的行合并到一块进行数据的处理。请问该如何弄、

PHPz
PHPz

学习是最好的投资!

reply all(5)
Peter_Zhu

Assume that the original excel has been sorted according to id:

import pandas as pd
table = pd.read_excel(r"....your file path")
rid = list(table['RevisionID'])
did = []
for i in range(len(table)-1):
    if rid[i] == rid[i+1]:
        did.append(i)
for i in did:
    del table[i:i+1]
pd.to_excel(r'...new file path')

After execution, a new excel will be formed listing the content you want.

大家讲道理

You can consider converting it to a csv file, and then just open the file for processing

巴扎黑

Reference material http://bbs.bathome.net/thread-39568-1-1....

PHPzhong

Research the xlrd library, or how to use python to modify .csv files (just convert .xlsx/.xls files into csv). There is also an openpyxl library, but it should not be able to merge as you require.

黄舟

Thought:

Use an array to record rows with the same ID, and then use another library to merge them

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template