Integrated data and time columns in smps txt files as a single column called Timestamp

This commit is contained in:
2024-02-14 09:31:59 +01:00
parent e082e066b1
commit e449021a6d

View File

@ -1,7 +1,7 @@
import pandas as pd
import matplotlib.pyplot as plt
import os
def read_smog_chamber_txt_files_as_dict(filename : str ,instrument_folder : str):
@ -47,6 +47,12 @@ def read_smog_chamber_txt_files_as_dict(filename : str ,instrument_folder : str)
df_numerical_attrs = df.select_dtypes(include ='number')
df_categorical_attrs = df.select_dtypes(exclude='number')
if instrument_folder == 'smps':
df_categorical_attrs['1_Timestamp'] = [ df_categorical_attrs.loc[i,'1_Date']+' '+df_categorical_attrs.loc[i,'2_Start Time'] for i in df.index]
df_categorical_attrs = df_categorical_attrs.drop(columns=['1_Date','2_Start Time'])
elif instrument_folder == 'gas':
df_categorical_attrs = df_categorical_attrs.rename(columns={'0_Date_Time' : '0_Timestamp'})
data_column_names = [item.encode("utf-8") for item in df_numerical_attrs.columns]
output_dict = { 'header_dict':header_dict,
'data': df_numerical_attrs.to_numpy(),
@ -65,13 +71,19 @@ def main():
#filename = 'M:\\gas\\20220705_000004_MSC_gases.txt' corrupted file
filename = 'M:\\gas\\20220726_101617_MSC_gases.txt'
instrument_folder = 'gas'
#filename = 'M:\\gas\\20220726_101617_MSC_gases.txt'
root_dir = '\\\\fs03\\Iron_Sulphate'
filename = 'M:\\smps\\20220726\\20220726_num.TXT'
instrument_folder = 'smps'
filename_path = os.path.join(root_dir,'smps\\20220726\\20220726_num.TXT')
result = read_smog_chamber_txt_files_as_dict(filename,instrument_folder)
instrument_folder = 'gas'
filename_path = os.path.join(root_dir,'gas\\20220726_101617_MSC_gases.txt')
result = read_smog_chamber_txt_files_as_dict(filename_path,instrument_folder)
print(':)')