我对Python还不太熟悉,所以任何帮助都将不胜感激。我试图在Linux上使用mdbtools从2000.mdb文件中提取数据并对其进行排序。到目前为止,我只需要获取.mdb文件并将所有表转储到.csv中。它造成了巨大的混乱,因为有很多文件需要处理。

我需要的是从特定的表中提取特定的排序数据。例如,我需要一个叫做“电压”的表。该表由许多周期组成,每个周期也有几行。周期通常按时间顺序进行,但在某些情况下,时间戳会被延迟记录下来。就像周期的第一行可以比周期的第一行有更晚的时间。我需要根据第一个或最后五个周期的时间提取周期的最新行。例如,在下表中,我需要第二行。Cycle# Time Data

1 100.59 34

1 101.34 54

1 98.78 45

2

2

2 ...........

这是我用的剧本。我正在使用命令python extract.py table_files.mdb.,但我希望使用./extract.py调用脚本。文件名的路径应该在脚本本身中。import sys, subprocess, os

DATABASE = sys.argv[1]

subprocess.call(["mdb-schema", DATABASE, "mysql"])

# Get the list of table names with "mdb-tables"

table_names = subprocess.Popen(["mdb-tables", "-1", DATABASE],

stdout=subprocess.PIPE).communicate()[0]

tables = table_names.splitlines()

print "BEGIN;" # start a transaction, speeds things up when importing

sys.stdout.flush()

# Dump each table as a CSV file using "mdb-export",

# converting " " in table names to "_" for the CSV filenames.

for table in tables:

if table != '':

filename = table.replace(" ","_") + ".csv"

file = open(filename, 'w')

print("Dumping " + table)

contents = subprocess.Popen(["mdb-export", DATABASE, table],

stdout=subprocess.PIPE).communicate()[0]

file.write(contents)

file.close()

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐