Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1"""Yearly sunspots data 1700-2008""" 

2from statsmodels.datasets import utils as du 

3 

4__docformat__ = 'restructuredtext' 

5 

6COPYRIGHT = """This data is public domain.""" 

7TITLE = __doc__ 

8SOURCE = """ 

9http://www.ngdc.noaa.gov/stp/solar/solarda3.html 

10 

11The original dataset contains monthly data on sunspot activity in the file 

12./src/sunspots_yearly.dat. There is also sunspots_monthly.dat. 

13""" 

14 

15DESCRSHORT = """Yearly (1700-2008) data on sunspots from the National 

16Geophysical Data Center.""" 

17 

18DESCRLONG = DESCRSHORT 

19 

20NOTE = """:: 

21 

22 Number of Observations - 309 (Annual 1700 - 2008) 

23 Number of Variables - 1 

24 Variable name definitions:: 

25 

26 SUNACTIVITY - Number of sunspots for each year 

27 

28 The data file contains a 'YEAR' variable that is not returned by load. 

29""" 

30 

31 

32def load_pandas(): 

33 data = _get_data() 

34 # TODO: time series 

35 endog = data.set_index(data.YEAR).SUNACTIVITY 

36 dataset = du.Dataset(data=data, names=list(data.columns), 

37 endog=endog, endog_name='volume') 

38 return dataset 

39 

40 

41def load(as_pandas=None): 

42 """ 

43 Load the yearly sunspot data and returns a data class. 

44 

45 Parameters 

46 ---------- 

47 as_pandas : bool 

48 Flag indicating whether to return pandas DataFrames and Series 

49 or numpy recarrays and arrays. If True, returns pandas. 

50 

51 Returns 

52 ------- 

53 Dataset instance: 

54 See DATASET_PROPOSAL.txt for more information. 

55 

56 Notes 

57 ----- 

58 This dataset only contains data for one variable, so the attributes 

59 data, raw_data, and endog are all the same variable. There is no exog 

60 attribute defined. 

61 """ 

62 return du.as_numpy_dataset(load_pandas(), as_pandas=as_pandas) 

63 

64 

65def _get_data(): 

66 return du.load_csv(__file__, 'sunspots.csv').astype(float)