Created
July 16, 2025 03:16
-
-
Save 0xAungkon/354e04ef9e2f611a2e9ee51be4f3620f to your computer and use it in GitHub Desktop.
read mdb(Microsoft Access) files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import subprocess | |
| import pandas as pd | |
| from io import StringIO | |
| mdb_file = 'att2000.mdb' | |
| att_table_name = 'CHECKINOUT' | |
| user_table_name = 'USERINFO' | |
| def get_df(table_name): | |
| # Export table using mdbtools | |
| result = subprocess.run(['mdb-export', mdb_file, table_name], stdout=subprocess.PIPE, check=True) | |
| csv_data = result.stdout.decode('utf-8') | |
| df = pd.read_csv(StringIO(csv_data)) | |
| return df | |
| # Convert CSV to DataFrame | |
| attendence_df=get_df(att_table_name) | |
| user_df=get_df(user_table_name) | |
| attendence_df = attendence_df.merge( | |
| user_df[['USERID', 'Name', 'Badgenumber']], | |
| on='USERID', | |
| how='left' | |
| ) | |
| del attendence_df['VERIFYCODE'] | |
| del attendence_df['SENSORID'] | |
| del attendence_df['Memoinfo'] | |
| del attendence_df['UserExtFmt'] | |
| del attendence_df['WorkCode'] | |
| attendence_df |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment