import pandas as pd

# df = pd.DataFrame()
# df["ind1"] = ["ind1", "ind2", "ind2"]
# df["ind2"] = None
# df["val1"] = range(3)
# df["val2"] = None

# print(df.pivot_table(index=["ind1"], columns=["val1", "ind1"], values=["val1"]))  # empty df columns index []
# print(df.pivot_table(index=["ind1"], columns=["val1"], values=["val1"]))  # ValueError: Grouper for 'val1' not 1-dimensional
# print(df.pivot_table(index=["ind1"], columns=["ind1"], values=["val1"]))  # ValueError: Grouper for 'ind1' not 1-dimensional
# df["ind2"] = df["ind1"]
# print(df.pivot_table(index=["ind1"], columns=["ind2"], values=["val1"]).reset_index().columns)  # multiindex

# print(df.empty)  # False

# res = df.pivot_table(index=["ind1", "ind2"], values="val1")
# print(res)  # empty df columns index []
# index [] 说明 index存在至少一列全为缺失值 只要如此 无论values如何 都是empty df
# 因此要求index全部列都不全为缺失值 在这个前提下:

# res = df.pivot_table(index="ind1", values=["val1", "val2"])
# print(res)  # 只要 values存在至少一列不全为缺失值 就不是empty df

# res = df.pivot_table(index="ind1", values="val2")
# print(res)  # 如果 values全部列都全为缺失值 输出empty df columns index []

# res = df.pivot_table(index="ind1", columns="ind2", values="val2")
# print(res)  # 与index同理

# df = pd.DataFrame(columns=["col1", "col2"])
# print(df.pivot_table(index="col1", values="col2"))  # df.empty 可视为 全部列都全为缺失值? 但反之不行
# print(df["col1"].isna().all())  # True  # 虽然 这种检验方法结果是True
# print(df["col1"].isna().any())  # False  # 但是 不可靠 所以 df.empty 不可视为 全部列都全为缺失值 只不过pivot_table结果相同

# pivot 结果为 empty df 可能的原因
# df.empty (index=[] 或columns=[] 或兼之)
# pivot.index 或pivot.columns 只要存在某列全为缺失值
# pivot.values 全部列全为缺失值

# pd.DataFrame(columns="col1")  # Index or array-like TypeError: Index(...) must be called with a collection of some kind, 'col1' was passed
# pd.DataFrame([[1, 2]], columns=[["col1", "col2"]]).to_html(r"d:\test.html")  # Columns: [(col1,), (col2,)]  但效果好像没问题
# df = pd.DataFrame([[1, 2]], columns=[["col1", "col2"]])  # 超过 2层list 就报错
# print(df.columns)  # 2层list multiindex
# print(df.equals(pd.DataFrame([[1, 2]], columns=["col1", "col2"])))  # False

# 先判断df.empty
# 再判断index
# 再判断columns
# 注意
# index columns list or str
# 输出 reset_index
# mutiindex的输出
# def pivot_empty(df, values=None, index=None, columns=None, aggfunc='mean', fill_value=None, margins=False, dropna=True, margins_name='All', observed=False, sort=True):
    # if index:
    #     if isinstance(index, str):
    # if df.empty:
    #
    # if index:
    #     if isinstance(index, str):
    #         df[index].isna().all()

# if __name__ == "__main__":
#     df = pd.DataFrame(columns=)
#     pivot_empty()