teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

3

add some codes

2019/07/24 00:13

投稿

Pablito
Pablito

スコア71

title CHANGED
File without changes
body CHANGED
@@ -57,5 +57,41 @@
57
57
 
58
58
  KeyError: 'yymm_purchase'
59
59
 
60
- 意味不明すぎて泣きそうです。。。
60
+ all codes below
61
+
61
- 助けて下さい。。。
62
+ ```Python
63
+ import pandas as pd
64
+ import numpy as np
65
+ import scipy as sp
66
+ import matplotlib.pyplot as plt
67
+ import matplotlib as mpl
68
+ import datetime as dt
69
+ import seaborn as sns
70
+ import io
71
+ from dateutil.parser import parse
72
+ %precision 3
73
+
74
+ data = pd.read_csv(rf'G:\共有.csv', engine='python',
75
+ encoding='cp932', dtype='object')
76
+
77
+ df = pd.read_csv(rf'G:\購買履歴', engine='python',
78
+ encoding='cp932', dtype='object')
79
+
80
+ #取り込んだデータの確認
81
+ data.info()
82
+ df.keys()
83
+ df.head()
84
+ data.drop_duplicates() #重複の削除
85
+
86
+ #chnage values into strings
87
+ data['cst'].astype(str)
88
+ data['Store'].astype(str)
89
+ data['Post'].astype(str)
90
+
91
+ data = data.drop(['date_n', 'birthday_n'], axis = 1)
92
+
93
+ #カラムをdatetime型に変換
94
+ df =pd.to_datetime(df['date_c'])
95
+ s = df.loc(['yymm_purchase'])
96
+ df = pd.to_datetime(s)
97
+ ```

2

changed the question

2019/07/24 00:13

投稿

Pablito
Pablito

スコア71

title CHANGED
File without changes
body CHANGED
@@ -10,6 +10,7 @@
10
10
 
11
11
  皆様もこういった経験はあるのでしょうか?
12
12
  これは環境の問題ですか???
13
+ 解決方法が分かる方はいらっしゃいますでしょうか???
13
14
 
14
15
  例えば、
15
16
  ```Python

1

added an example

2019/07/23 05:22

投稿

Pablito
Pablito

スコア71

title CHANGED
File without changes
body CHANGED
@@ -9,4 +9,52 @@
9
9
  自分でも原因が分かりません。。。
10
10
 
11
11
  皆様もこういった経験はあるのでしょうか?
12
- これは環境の問題ですか???
12
+ これは環境の問題ですか???
13
+
14
+ 例えば、
15
+ ```Python
16
+ df.keys()
17
+ ```
18
+ Index(['cst_id', 'date_purchase_c', 'date_purchase_n',** 'yymm_purchase',**
19
+ 'InsDate', 'dhms_InsDate', 'Trn_Type', 'rev', 'num', 'code', 'Brand',
20
+ 'MdName', 'TranKey', 'TranLineNo', 'Store_code', 'TerminalNo',
21
+ 'date_purchase', 'TranNo', 'StoreName', 'St_SalesChannel',
22
+ 'St_Hierarchy', 'Category_c', 'Item_c', 'Sub_Item_c', 'Category',
23
+ 'Item', 'Sub_Item', 'Sub_Item_2', 'FY'],
24
+ dtype='object')
25
+ なのに、
26
+ ```Python
27
+ df =pd.to_datetime(df['yymm_purchase'])
28
+ ```
29
+ ###エラーメッセージ
30
+ ---------------------------------------------------------------------------
31
+ KeyError Traceback (most recent call last)
32
+ <ipython-input-56-7d6126cfd80c> in <module>
33
+ ----> 1 df =pd.to_datetime(df['yymm_purchase'])
34
+
35
+ ~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\series.py in __getitem__(self, key)
36
+ 866 key = com.apply_if_callable(key, self)
37
+ 867 try:
38
+ --> 868 result = self.index.get_value(self, key)
39
+ 869
40
+ 870 if not is_scalar(result):
41
+
42
+ ~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_value(self, series, key)
43
+ 4373 try:
44
+ 4374 return self._engine.get_value(s, k,
45
+ -> 4375 tz=getattr(series.dtype, 'tz', None))
46
+ 4376 except KeyError as e1:
47
+ 4377 if len(self) > 0 and (self.holds_integer() or self.is_boolean()):
48
+
49
+ pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_value()
50
+
51
+ pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_value()
52
+
53
+ pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
54
+
55
+ pandas/_libs/index_class_helper.pxi in pandas._libs.index.Int64Engine._check_type()
56
+
57
+ KeyError: 'yymm_purchase'
58
+
59
+ 意味不明すぎて泣きそうです。。。
60
+ 助けて下さい。。。