You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.2 KiB
43 lines
1.2 KiB
import os
|
|
import pandas as pd
|
|
|
|
# 文件路径
|
|
input_file = r'D:\计量经济学\计量实验资料及作业要求\计量实验资料及作业要求\图文帖子原始信息计量实验使用.xlsx'
|
|
|
|
print("========================================")
|
|
print(" 检查数据结构")
|
|
print("========================================")
|
|
print(f"输入文件: {input_file}")
|
|
print()
|
|
|
|
# 检查文件是否存在
|
|
if not os.path.exists(input_file):
|
|
print("错误: 输入文件不存在!")
|
|
exit(1)
|
|
|
|
print(f"文件大小: {os.path.getsize(input_file) / 1024:.2f} KB")
|
|
|
|
# 读取原始数据
|
|
try:
|
|
print("正在读取原始数据...")
|
|
df = pd.read_excel(input_file)
|
|
print(f"成功读取 {len(df)} 行数据")
|
|
print(f"列数: {len(df.columns)}")
|
|
print(f"\n所有列名:")
|
|
for i, col in enumerate(df.columns, 1):
|
|
print(f"{i}. {col}")
|
|
|
|
print("\n前3行数据:")
|
|
print(df.head(3))
|
|
|
|
print("\n数据类型:")
|
|
print(df.dtypes)
|
|
|
|
print("\n========================================")
|
|
print(" 数据结构检查完成")
|
|
print("========================================")
|
|
|
|
except Exception as e:
|
|
print(f"处理文件时出错: {str(e)}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
|