pandas使用
1 import pandas as pd 2 3 #读取txt格式的表格文件 4 pd.read_tables("***.txt",delim_whitespace=True) 5 #delim_whitespace=True意思每个值用空格分开 6 7 #读取csv格式的文件 8 data = pd.read_csv("***.csv") 9 data.head(2) #查看前两行 10 data.columns #查看全有栏目 11 data.index #查看所有索引 12 data.loc[0] #0是索引可以替换,意思查看索引为0的一行
在读取log文件,用于生成文件名集合。
1 >>> import pandas as pd 2 >>> dates = pd.date_range(pd.to_datetime('2017-01-01'),pd.to_datetime('2018-04-0 3 4'),freq='M') 4 >>> type(dates) 5 <class 'pandas.core.indexes.datetimes.DatetimeIndex'> 6 >>> dates[:10] 7 DatetimeIndex(['2017-01-31', '2017-02-28', '2017-03-31', '2017-04-30', 8 '2017-05-31', '2017-06-30', '2017-07-31', '2017-08-31', 9 '2017-09-30', '2017-10-31'], 10 dtype='datetime64[ns]', freq='M') 11 >>> for i in dates: 12 ... print(i) 13 ... 14 2017-01-31 00:00:00 15 2017-02-28 00:00:00 16 2017-03-31 00:00:00 17 2017-04-30 00:00:00 18 2017-05-31 00:00:00 19 2017-06-30 00:00:00 20 2017-07-31 00:00:00 21 2017-08-31 00:00:00 22 2017-09-30 00:00:00 23 2017-10-31 00:00:00 24 2017-11-30 00:00:00 25 2017-12-31 00:00:00 26 2018-01-31 00:00:00 27 2018-02-28 00:00:00 28 2018-03-31 00:00:00 29 >>> dates = pd.date_range(pd.to_datetime('2017-01-01'),pd.to_datetime('2018-04-0 30 4')) 31 >>> dates[:10] 32 DatetimeIndex(['2017-01-01', '2017-01-02', '2017-01-03', '2017-01-04', 33 '2017-01-05', '2017-01-06', '2017-01-07', '2017-01-08', 34 '2017-01-09', '2017-01-10'], 35 dtype='datetime64[ns]', freq='D') 36 >>>