LoginSignup
0
0

More than 3 years have passed since last update.

pandas.read_excelで読み込んだ24時以降の時間は隣接するセルによってデータ型が変わる?

Last updated at Posted at 2020-10-28
  • 環境
    • macOS Catalina バージョン10.15.7
    • Microsoft Excel for Mac バージョン16.42
    • Python 3.8.5
    • pandas 1.1.3

ふと気がついていろいろ実験してみた。
上下左右(斜め除く)で隣接するセルが
「24時以降がある」場合は*pandas.Timestamp*
「24時以降がない」場合はdatetime.datetime
になる。とも思ったがそうでもないらしい。どういう決まりなんだろう?

  • ()の外は表示される値
  • ()の中は入力されている値
  • 書式は全て[ユーザー定義]の[h]:mm

パターン1

Excel
A
Excel
B
> 読込後の型
A
読込後の型
B
1 10:00
(10:00:00)
26:00
(1900/1/1 2:00:00)
> datetime.time pandas.Timestamp
2 24:10
(1900/1/1 0:10:00)
26:00
(1900/1/1 2:00:00)
> pandas.Timestamp pandas.Timestamp
3 24:40
(1900/1/1 0:40:00)
26:00
(1900/1/1 2:00:00)
> pandas.Timestamp pandas.Timestamp

パターン2

Excel
A
Excel
B
> 読込後の型
A
読込後の型
B
1 10:00
(10:00:00)
26:00
(1900/1/1 2:00:00)
> datetime.time pandas.Timestamp
2 10:00
(10:00:00)
26:00
(1900/1/1 2:00:00)
> datetime.time pandas.Timestamp
3 24:40
(1900/1/1 0:40:00)
26:00
(1900/1/1 2:00:00)
> pandas.Timestamp pandas.Timestamp

パターン3

Excel
A
Excel
B
> 読込後の型
A
読込後の型
B
1 10:00
(10:00:00)
26:00
(1900/1/1 2:00:00)
> datetime.time pandas.Timestamp
2 10:00
(10:00:00)
26:00
(1900/1/1 2:00:00)
> datetime.time pandas.Timestamp
3 10:00
(10:00:00)
26:00
(1900/1/1 2:00:00)
> datetime.time pandas.Timestamp

パターン4

Excel
A
Excel
B
> 読込後の型
A
読込後の型
B
1 10:00
(10:00:00)
18:00
(18:00:00)
> datetime.time datetime.time
2 10:00
(10:00:00)
26:00
(1900/1/1 2:00:00)
> datetime.time datetime.datetime
3 10:00
(10:00:00)
26:00
(1900/1/1 2:00:00)
> datetime.time datetime.datetime

パターン5

Excel
A
Excel
B
> 読込後の型
A
読込後の型
B
1 10:00
(10:00:00)
26:00
(1900/1/1 2:00:00)
> datetime.time datetime.datetime
2 10:00
(10:00:00)
23:00
(23:00:00)
> datetime.time datetime.time
3 10:00
(10:00:00)
26:00
(1900/1/1 2:00:00)
> datetime.time datetime.datetime

パターン6

Excel
A
Excel
B
> 読込後の型
A
読込後の型
B
1 10:00
(10:00:00)
18:00
(18:00:00)
> datetime.time datetime.time
2 10:00
(10:00:00)
26:00
(1900/1/1 2:00:00)
> datetime.time datetime.datetime
3 24:40
(1900/1/1 0:40:00)
26:00
(1900/1/1 2:00:00)
> pandas.Timestamp pandas.Timestamp

パターン7

Excel
A
Excel
B
> 読込後の型
A
読込後の型
B
1 10:00
(10:00:00)
23:00
(23:00:00)
> datetime.time datetime.time
2 25:00
(1900/1/1 1:00:00)
26:00
(1900/1/1 2:00:00)
> pandas.Timestamp pandas.Timestamp
3 26:00
(1900/1/1 2:00:00)
23:00
(23:00:00)
> datetime.datetime datetime.time
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0