简体   繁体   English

比较列的标签 python

[英]Compare columns' labels python

I have 2 xlsx files with multiple tabs, and each tab has multiple columns with labels.我有 2 个带有多个选项卡的 xlsx 文件,每个选项卡都有多个带标签的列。 How to check which tab has identical columns from those files?如何从这些文件中检查哪个选项卡具有相同的列? If identical, how to show those tabs?如果相同,如何显示这些选项卡? If not, how to show the diff?如果没有,如何显示差异?

Examples:例子:

tabfile1 = [ab, ac, ad, ae, ad]
tabfile2 = [ac, bd, ae, be]

labelFile1.tab(ac) = [data, huruf, angka]
labelFile2.tab(ac) = [data, huruf, ascii, angka] 

Here is a way to read file and get to know all the tabs along with label names这是一种读取文件并了解所有选项卡以及 label 名称的方法

import glob
import pandas as pd
all_files = glob.glob("*.xlsx")
for filename in all_files:
    print('Name of the file',filename)
    f = pd.ExcelFile(filename)
    sheet_names = f.sheet_names
    for sheet_name in sheet_names:
        print(f"{filename} , {sheet_name} ......")
        df = pd.read_excel(filename,sheet_name=sheet_name)
        print("{sheet_name} has following lables",df.columns)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM