質問編集履歴

3

add some codes

2019/07/24 00:13

投稿

Pablito
Pablito

スコア71

test CHANGED
File without changes
test CHANGED
@@ -116,6 +116,78 @@
116
116
 
117
117
 
118
118
 
119
- 意味不明すぎて泣きそうです。。。
119
+ all codes below
120
120
 
121
+
122
+
121
- 助けて下さい。。。
123
+ ```Python
124
+
125
+ import pandas as pd
126
+
127
+ import numpy as np
128
+
129
+ import scipy as sp
130
+
131
+ import matplotlib.pyplot as plt
132
+
133
+ import matplotlib as mpl
134
+
135
+ import datetime as dt
136
+
137
+ import seaborn as sns
138
+
139
+ import io
140
+
141
+ from dateutil.parser import parse
142
+
143
+ %precision 3
144
+
145
+
146
+
147
+ data = pd.read_csv(rf'G:\共有.csv', engine='python',
148
+
149
+ encoding='cp932', dtype='object')
150
+
151
+
152
+
153
+ df = pd.read_csv(rf'G:\購買履歴', engine='python',
154
+
155
+ encoding='cp932', dtype='object')
156
+
157
+
158
+
159
+ #取り込んだデータの確認
160
+
161
+ data.info()
162
+
163
+ df.keys()
164
+
165
+ df.head()
166
+
167
+ data.drop_duplicates() #重複の削除
168
+
169
+
170
+
171
+ #chnage values into strings
172
+
173
+ data['cst'].astype(str)
174
+
175
+ data['Store'].astype(str)
176
+
177
+ data['Post'].astype(str)
178
+
179
+
180
+
181
+ data = data.drop(['date_n', 'birthday_n'], axis = 1)
182
+
183
+
184
+
185
+ #カラムをdatetime型に変換
186
+
187
+ df =pd.to_datetime(df['date_c'])
188
+
189
+ s = df.loc(['yymm_purchase'])
190
+
191
+ df = pd.to_datetime(s)
192
+
193
+ ```

2

changed the question

2019/07/24 00:13

投稿

Pablito
Pablito

スコア71

test CHANGED
File without changes
test CHANGED
@@ -21,6 +21,8 @@
21
21
  皆様もこういった経験はあるのでしょうか?
22
22
 
23
23
  これは環境の問題ですか???
24
+
25
+ 解決方法が分かる方はいらっしゃいますでしょうか???
24
26
 
25
27
 
26
28
 

1

added an example

2019/07/23 05:22

投稿

Pablito
Pablito

スコア71

test CHANGED
File without changes
test CHANGED
@@ -21,3 +21,99 @@
21
21
  皆様もこういった経験はあるのでしょうか?
22
22
 
23
23
  これは環境の問題ですか???
24
+
25
+
26
+
27
+ 例えば、
28
+
29
+ ```Python
30
+
31
+ df.keys()
32
+
33
+ ```
34
+
35
+ Index(['cst_id', 'date_purchase_c', 'date_purchase_n',** 'yymm_purchase',**
36
+
37
+ 'InsDate', 'dhms_InsDate', 'Trn_Type', 'rev', 'num', 'code', 'Brand',
38
+
39
+ 'MdName', 'TranKey', 'TranLineNo', 'Store_code', 'TerminalNo',
40
+
41
+ 'date_purchase', 'TranNo', 'StoreName', 'St_SalesChannel',
42
+
43
+ 'St_Hierarchy', 'Category_c', 'Item_c', 'Sub_Item_c', 'Category',
44
+
45
+ 'Item', 'Sub_Item', 'Sub_Item_2', 'FY'],
46
+
47
+ dtype='object')
48
+
49
+ なのに、
50
+
51
+ ```Python
52
+
53
+ df =pd.to_datetime(df['yymm_purchase'])
54
+
55
+ ```
56
+
57
+ ###エラーメッセージ
58
+
59
+ ---------------------------------------------------------------------------
60
+
61
+ KeyError Traceback (most recent call last)
62
+
63
+ <ipython-input-56-7d6126cfd80c> in <module>
64
+
65
+ ----> 1 df =pd.to_datetime(df['yymm_purchase'])
66
+
67
+
68
+
69
+ ~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\series.py in __getitem__(self, key)
70
+
71
+ 866 key = com.apply_if_callable(key, self)
72
+
73
+ 867 try:
74
+
75
+ --> 868 result = self.index.get_value(self, key)
76
+
77
+ 869
78
+
79
+ 870 if not is_scalar(result):
80
+
81
+
82
+
83
+ ~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_value(self, series, key)
84
+
85
+ 4373 try:
86
+
87
+ 4374 return self._engine.get_value(s, k,
88
+
89
+ -> 4375 tz=getattr(series.dtype, 'tz', None))
90
+
91
+ 4376 except KeyError as e1:
92
+
93
+ 4377 if len(self) > 0 and (self.holds_integer() or self.is_boolean()):
94
+
95
+
96
+
97
+ pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_value()
98
+
99
+
100
+
101
+ pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_value()
102
+
103
+
104
+
105
+ pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
106
+
107
+
108
+
109
+ pandas/_libs/index_class_helper.pxi in pandas._libs.index.Int64Engine._check_type()
110
+
111
+
112
+
113
+ KeyError: 'yymm_purchase'
114
+
115
+
116
+
117
+ 意味不明すぎて泣きそうです。。。
118
+
119
+ 助けて下さい。。。