export tables from database to mdf file

311 views Asked by At

i am python beginner. i have Database that has 5 tables, i use python to export all those tables to mdf file using asammdf.

path_data = os.path.join('..\\Data', 'db_2021-05-06_11-49-42_day.db')
con = sqlite3.connect(path_data)
cursor = con.cursor()
cursor.execute('SELECT name FROM sqlite_master WHERE type="table";')
tables = cursor.fetchall()
print(tables)

sigs = []
for equipment in tables:
    df = pd.read_sql_query('select * from' + equipment , con)
    df_small = df[0:1000]
    df_time = (df_small['ts']-df_small.iloc[0]['ts'])
    df_time_int = df_time.astype('int64')
    for signal in df_small.columns.to_list():
        test_signal = Signal(samples=df_small[signal],  timestamps=df_time,
                        name=signal,
                        unit='A')
        sigs.append(test_signal)
mdf.append(sigs)
mdf.save('test_complete.mf4', overwrite=True)

and i find this error:

TypeError                                 Traceback (most recent call last)
c:\Users\Muhammad Lazaroni\SW_Workspace\MeasurementMerger\Scripts\merger.py in 
      37 # table_list= list[tables]
      38 for equipment in tables:
----> 39     df = pd.read_sql_query('select * from' + equipment , con)
      40     df_small = df[0:1000]
      41     df_time = (df_small['ts']-df_small.iloc[0]['ts'])

TypeError: can only concatenate str (not "tuple") to str
1

There are 1 answers

1
Chi On

The phrase "can only concatenate str (not "tuple") to str" means "trying to concatenate str and non-str (tuple)". Therefore, we need to match the type of either one we are trying to combine.

df = pd.read_sql_query('select * from' + str(equipment) , con)

df = pd.read_sql_query('select * from' + equipment , str(con))

Try either of these.