import pandas as pd

def read_and_analyze_excel(file_path, sheet_name=0):
    """
    Reads an Excel file and provides basic analytics.
    
    :param file_path: Path to the .xlsx file
    :param sheet_name: Sheet name (str or int). Use None to read all sheets.
    :return: Dictionary with sheet names as keys, and each value is a tuple (DataFrame, analytics)
    """
    # Read the Excel file
    data = pd.read_excel(file_path, sheet_name=sheet_name, engine='openpyxl')
    
    df = data
    analytics = {
        "Head": df.head(),
        "Shape": df.shape,
        "Dtypes": df.dtypes,
        "Missing Values": df.isnull().sum(),
        "Describe": df.describe()
    }
    #value_counts = df["Mã hàng"].value_counts()
    #print(value_counts)
    #print(df["Mã hàng"].unique())

    return df, analytics
def getCodes(code):
    arrs = code.split(',')
    results = []
    for item in arrs:
        if item.find('\n') == -1:
            if item.strip() not in results:
                results.append(item.strip())
        else:
            narrs = item.strip().split('\n')
            for nitem in narrs:
                if nitem.strip() not in results:
                    results.append(nitem.strip())   
    results

file_path = 'crm.xlsx'
df, analytics = read_and_analyze_excel(file_path, "Book2")

# # Print summary
# for key, value in analytics.items():
#     print(f"\n--- {key} ---")
#     print(value)
code_results = []
codes = df["Mã hàng"].unique()
for code in codes:
    print (code)
    if code != None and code.strip() != "":
        code_results = set(code_results + getCodes(code))

print (code_results)