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.
 
 
 

54 lines
1.9 KiB

import os
import pandas as pd
# 文件路径
input_file = r'D:\计量经济学\计量实验资料及作业要求\计量实验资料及作业要求\图文帖子实验数据(新).xlsx'
output_file = r'D:\计量经济学\计量实验资料及作业要求\计量实验资料及作业要求\UGC回归数据.xlsx'
print("========================================")
print(" 简单数据测试")
print("========================================")
print(f"输入文件: {input_file}")
print(f"输出文件: {output_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"列名: {list(df.columns)}")
# 简单处理:创建一个只包含前5列的新文件
print("\n创建测试文件...")
test_data = df.head(100) # 只取前100行
test_output = r'D:\计量经济学\计量实验资料及作业要求\计量实验资料及作业要求\test_output.xlsx'
test_data.to_excel(test_output, index=False)
print(f"测试文件已创建: {test_output}")
print(f"测试文件大小: {os.path.getsize(test_output) / 1024:.2f} KB")
# 验证测试文件
if os.path.exists(test_output):
df_test = pd.read_excel(test_output)
print(f"测试文件行数: {len(df_test)}")
print(f"测试文件列数: {len(df_test.columns)}")
else:
print("测试文件创建失败!")
print()
print("========================================")
print(" 测试完成")
print("========================================")
except Exception as e:
print(f"处理文件时出错: {str(e)}")
import traceback
traceback.print_exc()