1

I have a column(date field) in the txt file(textfile_A) and i am reading max date in that column and passing that max_date value into my sql query , finally i am trying to export my results into txt(textfile_B) like in below format ,i have tried the below code and getting my results in txt with datatype of values.

my dataframe output :

0 [74000017966,0,1,1,7694,2019-08-08-01:18]

Results in my txt file: 0 (Decimal('74000017966'), 0, 1, 1, 7694, datetime.datetime(2019, 8, 3, 1, 8, 58, 155000)

trying to get readble format in txt file>

74000015215.0 0 1 1 7984 2019-08-01 22:01

import pyodbc
import numpy as np
import datetime
import time
import pandas as pd


cnxn_informix = pyodbc.connect(dsn='dsn1')

df_1 = pd.read_csv(r'C:\textfile_A', delimiter = "\t")
max_startdate = df_1['startdatetime'].max()
mod_date,un_char = max_startdate.split(".")
cursor = cnxn_informix.cursor()
out = cursor.execute("SELECT * FROM table1 where startdatetime >=   ?" ,mod_date)

df_2 = pd.DataFrame(out)


np.savetxt(r"C:\textfile_B", df_2.values,fmt='%s',delimiter = '\t')
Rahul
  • 467
  • 1
  • 8
  • 24

1 Answers1

0

df_2 = pd.DataFrame(out) produces a DataFrame with a single column containing a list of all the values for the entire row. If you want a proper DataFrame with individual columns then you should use something like

df_2 = pd.DataFrame([list(row) for row in out])
Gord Thompson
  • 116,920
  • 32
  • 215
  • 418