質問編集履歴

2

補足の追加

2023/01/17 14:02

投稿

yoshitaka_1020
yoshitaka_1020

スコア17

test CHANGED
File without changes
test CHANGED
@@ -29,8 +29,10 @@
29
29
 
30
30
  ### 補足情報(FW/ツールのバージョンなど)
31
31
 
32
+ 1.
32
33
  Google Colab
33
34
 
35
+ 2.
34
36
  リストの内包表記のところでdatetimeのmonthを抜いているのでリスト内の型が想定していないようなデータ型をしている?と思い、以下のコードで確認しましたが、すべてintとして入っているため問題ないと結論づけました。
35
37
  ```python
36
38
  test = "2022-02-02 00:00:00,2022-03-01 00:00:00,2022-01-01 00:00:00"
@@ -45,3 +47,18 @@
45
47
  <class 'int'>
46
48
  ```
47
49
 
50
+ 3.
51
+ (ソース:https://dot-blog.jp/news/python-max-function/)このページ内にある以下のようなコードをColab内で実行しても同様のエラーが返ってくる
52
+ ```
53
+ x = [30, 20, 10, 40]
54
+ print(max(x))
55
+ ```
56
+ ```
57
+ ---------------------------------------------------------------------------
58
+ TypeError Traceback (most recent call last)
59
+ <ipython-input-139-465bd6f6712c> in <module>
60
+ 1 x = [30, 20, 10, 40]
61
+ ----> 2 print(max(x))
62
+
63
+ TypeError: 'int' object is not callable
64
+ ```

1

最終行に補足の追記

2023/01/17 13:50

投稿

yoshitaka_1020
yoshitaka_1020

スコア17

test CHANGED
File without changes
test CHANGED
@@ -10,9 +10,8 @@
10
10
  <ipython-input-123-d1ead93c94cf> in <module>
11
11
  3 test = [dt.strptime(i.strip().lower() , "%Y-%m-%d %H:%M:%S" ).month for i in test.split(",")]
12
12
  4 print(test)
13
- ----> 5 max_month = max(test)
13
+ ----> 5 max_month, min_month = [max(test),min(test)]
14
- 6 min_month = min(test)
15
- 7 x = ",\n".join([ f"IF(cp{i} = 1, 1, 0) AS cp{i}" for i in range(min_month , max_month + 1)])
14
+ 6 x = ",\n".join([ f"IF(cp{i} = 1, 1, 0) AS cp{i}" for i in range(min_month , max_month + 1)])
16
15
 
17
16
  TypeError: 'int' object is not callable
18
17
  ```
@@ -23,8 +22,7 @@
23
22
  from datetime import datetime as dt
24
23
  test = "2022-02-02 00:00:00,2022-03-01 00:00:00,2022-01-01 00:00:00"
25
24
  test = [dt.strptime(i.strip().lower() , "%Y-%m-%d %H:%M:%S" ).month for i in test.split(",")]
26
- max_month = max(test)
25
+ max_month,min_month = [max(test),min(test)]
27
- min_month = min(test)
28
26
  x = ",\n".join([ f"IF(cp{i} = 1, 1, 0) AS cp{i}" for i in range(min_month , max_month + 1)])
29
27
  print(x)
30
28
  ```
@@ -33,3 +31,17 @@
33
31
 
34
32
  Google Colab
35
33
 
34
+ リストの内包表記のところでdatetimeのmonthを抜いているのでリスト内の型が想定していないようなデータ型をしている?と思い、以下のコードで確認しましたが、すべてintとして入っているため問題ないと結論づけました。
35
+ ```python
36
+ test = "2022-02-02 00:00:00,2022-03-01 00:00:00,2022-01-01 00:00:00"
37
+ test = [dt.strptime(i.strip().lower() , "%Y-%m-%d %H:%M:%S" ).month for i in test.split(",")]
38
+ for i in test:
39
+ print(type(i))
40
+ ```
41
+ 以下出力
42
+ ```
43
+ <class 'int'>
44
+ <class 'int'>
45
+ <class 'int'>
46
+ ```
47
+