如何将日期时间数据导入到sqlite3?

发布于 2024-10-28 04:21:08 字数 767 浏览 1 评论 0原文

我有一个 CSV 文件,其中包含以下格式的时间戳:

 Datetime, Outdoor, Indoor
 01/01  01:00:00,24.5,21.3
 01/01  02:00:00,24.3,21.1
 01/01  03:00:00,24.1,21.1
 01/01  04:00:00,24.1,20.9
 01/01  05:00:00,25.,21.
 01/01  06:00:00,26.,21.
 01/01  07:00:00,26.6,20.3
 01/01  08:00:00,28.,21.
 01/01  09:00:00,28.9,21.5
 01/01  10:00:00,29.4,22.1
 01/01  11:00:00,30.,22.
 01/01  12:00:00,29.,23.
 01/01  13:00:00,28.4,22.9
 01/01  14:00:00,27.8,22.7
 01/01  15:00:00,27.3,22.3
 01/01  16:00:00,27.,22.
 01/01  17:00:00,26.,21.
 01/01  18:00:00,26.,21.
 01/01  19:00:00,26.3,21.4
 01/01  20:00:00,26.,21.
 01/01  21:00:00,25.9,21.1
 01/01  22:00:00,25.8,21.3
 01/01  23:00:00,25.6,21.4
 01/01  24:00:00,25.5,21.5

即日期时间格式为“%m/%d %H:%M:%S”。如何将其导入到 sqlite3 中?

I have a CSV file containing a timestamp in the following format:

 Datetime, Outdoor, Indoor
 01/01  01:00:00,24.5,21.3
 01/01  02:00:00,24.3,21.1
 01/01  03:00:00,24.1,21.1
 01/01  04:00:00,24.1,20.9
 01/01  05:00:00,25.,21.
 01/01  06:00:00,26.,21.
 01/01  07:00:00,26.6,20.3
 01/01  08:00:00,28.,21.
 01/01  09:00:00,28.9,21.5
 01/01  10:00:00,29.4,22.1
 01/01  11:00:00,30.,22.
 01/01  12:00:00,29.,23.
 01/01  13:00:00,28.4,22.9
 01/01  14:00:00,27.8,22.7
 01/01  15:00:00,27.3,22.3
 01/01  16:00:00,27.,22.
 01/01  17:00:00,26.,21.
 01/01  18:00:00,26.,21.
 01/01  19:00:00,26.3,21.4
 01/01  20:00:00,26.,21.
 01/01  21:00:00,25.9,21.1
 01/01  22:00:00,25.8,21.3
 01/01  23:00:00,25.6,21.4
 01/01  24:00:00,25.5,21.5

That is the datetime format is "%m/%d %H:%M:%S". How can I import this into sqlite3?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

树深时见影 2024-11-04 04:21:08

“01/01”不是日期。如果您的意思是“21.0”,请输出“21.0”,而不是“21.”。

编辑您的 csv 文件(或者更好的是,修复输出该垃圾的程序),使其看起来像这样。

2011-01-01  01:00:00,24.5,21.3
2011-01-01  02:00:00,24.3,21.1
2011-01-01  03:00:00,24.1,21.1
2011-01-01  04:00:00,24.1,20.9
2011-01-01  05:00:00,25.0,21.0
2011-01-01  06:00:00,26.0,21.0
2011-01-01  07:00:00,26.6,20.3
2011-01-01  08:00:00,28.0,21.0
2011-01-01  09:00:00,28.9,21.5
2011-01-01  10:00:00,29.4,22.1
2011-01-01  11:00:00,30.0,22.0
2011-01-01  12:00:00,29.0,23.0
2011-01-01  13:00:00,28.4,22.9
2011-01-01  14:00:00,27.8,22.7
2011-01-01  15:00:00,27.3,22.3
2011-01-01  16:00:00,27.0,22.0
2011-01-01  17:00:00,26.0,21.0
2011-01-01  18:00:00,26.0,21.0
2011-01-01  19:00:00,26.3,21.4
2011-01-01  20:00:00,26.0,21.0
2011-01-01  21:00:00,25.9,21.1
2011-01-01  22:00:00,25.8,21.3
2011-01-01  23:00:00,25.6,21.4
2011-01-01  24:00:00,25.5,21.5

然后设置分隔符并导入文件。

sqlite> .separator ','
sqlite> .import filename tablename

"01/01" isn't a date. If you mean "21.0", output "21.0", not "21.".

Edit your csv file (or better yet, fix the program that outputs that junk) so it looks like this.

2011-01-01  01:00:00,24.5,21.3
2011-01-01  02:00:00,24.3,21.1
2011-01-01  03:00:00,24.1,21.1
2011-01-01  04:00:00,24.1,20.9
2011-01-01  05:00:00,25.0,21.0
2011-01-01  06:00:00,26.0,21.0
2011-01-01  07:00:00,26.6,20.3
2011-01-01  08:00:00,28.0,21.0
2011-01-01  09:00:00,28.9,21.5
2011-01-01  10:00:00,29.4,22.1
2011-01-01  11:00:00,30.0,22.0
2011-01-01  12:00:00,29.0,23.0
2011-01-01  13:00:00,28.4,22.9
2011-01-01  14:00:00,27.8,22.7
2011-01-01  15:00:00,27.3,22.3
2011-01-01  16:00:00,27.0,22.0
2011-01-01  17:00:00,26.0,21.0
2011-01-01  18:00:00,26.0,21.0
2011-01-01  19:00:00,26.3,21.4
2011-01-01  20:00:00,26.0,21.0
2011-01-01  21:00:00,25.9,21.1
2011-01-01  22:00:00,25.8,21.3
2011-01-01  23:00:00,25.6,21.4
2011-01-01  24:00:00,25.5,21.5

Then set the separator and import the file.

sqlite> .separator ','
sqlite> .import filename tablename
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文