Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
166 views
in Technique[技术] by (71.8m points)

Inserting TimeStamp Column from List to MYSQL using Python

I have a List like shown below (The list has been obtained by converting a pandas dataframe to a list. The pandas dataframe is obtained from an excel):

  • L = [[3982, 36308220021, Timestamp('2017-07-01 14:10:37'), '', Timestamp('2017-07-01 14:20:48'), '', 0, 0]]

Note: L is actually a nested list with more than 5000 entries.

I am inserting the values in MySQL using python . There I have defined the column as "dateACW DATETIME" during CREATE TABLE operations. Similar column names have been defined for other Timestamp values from the list. During insertion in MySQL, it gives following error: "AttributeError: 'Timestamp' object has no attribute 'translate'". I tried using TIMESTAMP datatype instead of DATETIME. That did not help. Please help me out with explanation on whats the problem.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can probably use to_pydatetime() function to convert it to datetime.

timestamp = pd.Timestamp('2017-07-01 14:10:37', tz=None)

timestamp.to_pydatetime()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...