Last active
November 25, 2019 08:28
-
-
Save sabopy/b3145c17ac4f7de904b3c918e2dc487f to your computer and use it in GitHub Desktop.
複数のテキストファイルをpandasでひとつにまとめる。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import glob | |
import pandas as pd | |
datafile_list = glob.glob('data/*.xlsx') | |
datafile_list | |
''' | |
['data/Dino_2018_0930_.xlsx', | |
'data/Dino_2018_0909_1002.xlsx', | |
'data/Dino_2018_0923_0929.xlsx', | |
'data/Dino_2018_0916_0922.xlsx'] | |
''' | |
datafile_list.sort() | |
datafile_list | |
''' | |
['data/Dino_2018_0909_1002.xlsx', | |
'data/Dino_2018_0916_0922.xlsx', | |
'data/Dino_2018_0923_0929.xlsx', | |
'data/Dino_2018_0930_.xlsx'] | |
''' | |
data_files = [pd.read_excel(datafile_list[i],parse_dates=[0]) for i in range(len(datafile_list))] | |
all_data = pd.concat(data_files,ignore_index=True) | |
all_data | |
''' | |
Date Score Dead | |
0 2018-09-09 2089 bird_m | |
1 2018-09-10 5294 bird_h | |
2 2018-09-11 6588 sabo_4 | |
3 2018-09-12 8901 sabo_2 | |
4 2018-09-13 7159 bird_m | |
5 2018-09-14 9498 bird_m | |
6 2018-09-15 17118 sabo_4 | |
7 2018-09-16 5936 bird_m | |
8 2018-09-17 9314 sabo_4 | |
9 2018-09-18 5468 bird_m | |
10 2018-09-19 11479 sabo_4 | |
11 2018-09-20 9017 sabo_3 | |
12 2018-09-21 4706 sabo_3 | |
13 2018-09-22 7820 sabo_4 | |
14 2018-09-23 6418 sabo_1 | |
15 2018-09-24 16065 sabo_4 | |
16 2018-09-25 5201 sabo_1 | |
17 2018-09-26 8995 bird_m | |
18 2018-09-27 22515 sabo_2 | |
19 2018-09-28 8436 bird_h | |
20 2018-09-29 13638 sabo_1 | |
21 2018-09-30 12621 bird_h | |
22 2018-10-01 5256 sabo_4 | |
23 2018-10-02 19878 sabo_1 | |
24 2018-09-16 5936 bird_m | |
25 2018-09-17 9314 sabo_4 | |
26 2018-09-18 5468 bird_m | |
27 2018-09-19 11479 sabo_4 | |
28 2018-09-20 9017 sabo_3 | |
29 2018-09-21 4706 sabo_3 | |
30 2018-09-22 7820 sabo_4 | |
31 2018-09-23 6418 sabo_1 | |
32 2018-09-24 16065 sabo_4 | |
33 2018-09-25 5201 sabo_1 | |
34 2018-09-26 8995 bird_m | |
35 2018-09-27 22515 sabo_2 | |
36 2018-09-28 8436 bird_h | |
37 2018-09-29 13638 sabo_1 | |
38 2018-09-30 12621 bird_h | |
39 2018-10-01 5256 sabo_4 | |
40 2018-10-02 19878 sabo_1 | |
41 2018-10-03 4873 sabo_1 | |
42 2018-10-04 8092 sabo_2 | |
43 2018-10-05 2093 sabo_2 | |
44 2018-10-06 7931 sabo_1 | |
''' | |
all_data.to_csv("all_data.tsv",sep='\t', index=False) | |
all_data.to_excel('all_data.xlsx', index=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment