Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88087

Cannot write to Excel worksheet with valid date format with Pandas

$
0
0

The background:

1, used Python to execute the SQL and saved the output into DataFrame format using Pandas.

2, appended the output to my existing excel file as one new worksheet.

Below is my code:

from pandas import ExcelWriter

sql_20 = ''''''

db = cx_Oracle.connect('*****', '*******', '**********')
conn = db.cursor()

conn.execute(sql_20)
df = pandas.read_sql_query(sql_20,db)
print(df)

with ExcelWriter('GUCS6J-Job Data.xlsx', mode='a') as writer:
    df.to_excel(writer, sheet_name=str(20))
writer.save()

Database: Oracle

Column A data type: date

The SQL result from Oracle:

enter image description here

The DataFrame print from Python:

enter image description here

So far so good


But what I got in the excel worksheet:

enter image description here

enter image description here

I am curious why I got the '##################' and the value of this cell is -693594 in the excel.

I hope I can get the same result as the DataFrame print in the excel file.


Viewing all articles
Browse latest Browse all 88087

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>