質問編集履歴
4
change title
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
pandas で
|
1
|
+
pandas で YYYY-03-01 から (YYYY+1)-02-29 を YYYY 年度としてまとめたい
|
body
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
### 例
|
2
2
|
- 2010-03-01 から 2011-02-29
|
3
3
|
- 2010年度
|
4
4
|
|
3
fix table
title
CHANGED
File without changes
|
body
CHANGED
@@ -2,28 +2,23 @@
|
|
2
2
|
- 2010-03-01 から 2011-02-29
|
3
3
|
- 2010年度
|
4
4
|
|
5
|
-
##
|
5
|
+
#### (理想)
|
6
|
+
| | a | b |
|
7
|
+
| :---: | :---: | :---: |
|
8
|
+
| 2010 | 8 | 23 |
|
9
|
+
| 2011 | 15 | 30 |
|
6
10
|
|
7
|
-
|
11
|
+
#### 元データ
|
8
|
-
|:--|:--:|--:|
|
9
|
-
|2010-03-01|1|6|
|
10
|
-
|2010-06-30|2|7|
|
11
|
-
|2010-10-30|3|8|
|
12
|
-
|2011-02-29|4|9|
|
13
|
-
|2012-06-30|5|10|
|
14
12
|
|
15
|
-
|
13
|
+
| ymd | a | b |
|
14
|
+
| :-- | :--: | --: |
|
15
|
+
| 2010-03-01 | 1 | 6 |
|
16
|
+
| 2011-01-02 | 3 | 8 |
|
17
|
+
| 2011-02-29 | 4 | 9 |
|
18
|
+
| 2012-04-30 | 5 | 10 |
|
19
|
+
| 2012-07-20 | 5 | 10 |
|
20
|
+
| 2013-02-20 | 5 | 10 |
|
16
21
|
|
17
|
-
```python
|
18
|
-
df = pd.read_csv("hoge.csv", parse_dates=['ymd'],index_col=0)
|
19
|
-
df.groupby().sum()
|
20
|
-
|
21
|
-
# 2010年度のaは
|
22
|
-
| 2010 | 10 |
|
23
|
-
| 2011 | xx |
|
24
|
-
...
|
25
|
-
```
|
26
|
-
|
27
22
|
## 年別は以下で可能
|
28
23
|
|
29
24
|
- `YYYY0101` から `YYYY1231` の区間で集計している?
|
2
A
title
CHANGED
File without changes
|
body
CHANGED
@@ -30,4 +30,12 @@
|
|
30
30
|
|
31
31
|
```python
|
32
32
|
df.groupby(df.index.year).sum()
|
33
|
+
```
|
34
|
+
|
35
|
+
## 直接指定すれば解決できる
|
36
|
+
|
37
|
+
- 自動化?したい
|
38
|
+
|
39
|
+
```python
|
40
|
+
df['2010-03':'2011-02'].sum()
|
33
41
|
```
|
1
add
title
CHANGED
File without changes
|
body
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
- 2010-03-01 から 2011-02-29
|
3
3
|
- 2010年度
|
4
4
|
|
5
|
+
## hoge.csv
|
6
|
+
|
5
7
|
|ymd|a|b|
|
6
8
|
|:--|:--:|--:|
|
7
9
|
|2010-03-01|1|6|
|
@@ -13,10 +15,19 @@
|
|
13
15
|
# 理想
|
14
16
|
|
15
17
|
```python
|
18
|
+
df = pd.read_csv("hoge.csv", parse_dates=['ymd'],index_col=0)
|
16
19
|
df.groupby().sum()
|
17
20
|
|
18
21
|
# 2010年度のaは
|
19
22
|
| 2010 | 10 |
|
20
23
|
| 2011 | xx |
|
21
24
|
...
|
25
|
+
```
|
26
|
+
|
27
|
+
## 年別は以下で可能
|
28
|
+
|
29
|
+
- `YYYY0101` から `YYYY1231` の区間で集計している?
|
30
|
+
|
31
|
+
```python
|
32
|
+
df.groupby(df.index.year).sum()
|
22
33
|
```
|