コード例 #1
0
ファイル: test_fred.py プロジェクト: zonca/pandas
    def test_fred_parts(self):
        import numpy as np

        start = datetime(2010, 1, 1)
        end = datetime(2013, 01, 27)
        df = web.get_data_fred("CPIAUCSL", start, end)
        assert df.ix['2010-05-01'] == 217.23

        t = np.array(df.CPIAUCSL.tolist())
        assert np.issubdtype(t.dtype, np.floating)
        assert t.shape == (37, )

        # Test some older ones:
        expected = [[576.7], [962.9], [684.7], [848.3], [933.3]]
        result = web.get_data_fred("A09024USA144NNBR", start="1915").ix[:5]
        assert (result.values == expected).all()
コード例 #2
0
ファイル: test_fred.py プロジェクト: Black-Milk/pandas
    def test_fred_parts(self):
        import numpy as np

        start = datetime(2010, 1, 1)
        end = datetime(2013, 01, 27)
        df = web.get_data_fred("CPIAUCSL", start, end)
        assert df.ix["2010-05-01"] == 217.23

        t = np.array(df.CPIAUCSL.tolist())
        assert np.issubdtype(t.dtype, np.floating)
        assert t.shape == (37,)

        # Test some older ones:
        expected = [[576.7], [962.9], [684.7], [848.3], [933.3]]
        result = web.get_data_fred("A09024USA144NNBR", start="1915").ix[:5]
        assert (result.values == expected).all()
コード例 #3
0
ファイル: test_data.py プロジェクト: guyrt/pandas
 def test_fred_part2(self):
     expected = [[576.7],
                 [962.9],
                 [684.7],
                 [848.3],
                 [933.3]]
     result = web.get_data_fred("A09024USA144NNBR", start="1915").ix[:5]
     tm.assert_numpy_array_equal(result.values, np.array(expected))
コード例 #4
0
ファイル: test_data.py プロジェクト: brotchie/pandas
 def test_fred_part2(self):
     expected = [[576.7],
                 [962.9],
                 [684.7],
                 [848.3],
                 [933.3]]
     result = web.get_data_fred("A09024USA144NNBR", start="1915").ix[:5]
     assert_array_equal(result.values, np.array(expected))
コード例 #5
0
ファイル: test_data.py プロジェクト: esc/pandas
    def test_fred_parts(self):
        start = datetime(2010, 1, 1)
        end = datetime(2013, 1, 27)
        df = web.get_data_fred("CPIAUCSL", start, end)
        self.assertEqual(df.ix['2010-05-01'], 217.23)

        t = df.CPIAUCSL.values
        assert np.issubdtype(t.dtype, np.floating)
        self.assertEqual(t.shape, (37,))
コード例 #6
0
ファイル: test_data.py プロジェクト: stenri/pandas
    def test_fred_parts(self):
        start = datetime(2010, 1, 1)
        end = datetime(2013, 1, 27)
        df = web.get_data_fred("CPIAUCSL", start, end)
        self.assertEqual(df.ix['2010-05-01'], 217.23)

        t = df.CPIAUCSL.values
        assert np.issubdtype(t.dtype, np.floating)
        self.assertEqual(t.shape, (37, ))
コード例 #7
0
ファイル: test_data.py プロジェクト: guyrt/pandas
    def test_fred_parts(self):
        raise nose.SkipTest('buggy as of 2/18/14; maybe a data revision?')

        start = datetime(2010, 1, 1)
        end = datetime(2013, 1, 27)
        df = web.get_data_fred("CPIAUCSL", start, end)
        self.assertEqual(df.ix['2010-05-01'][0], 217.23)

        t = df.CPIAUCSL.values
        self.assertTrue(np.issubdtype(t.dtype, np.floating))
        self.assertEqual(t.shape, (37,))
コード例 #8
0
    def test_fred_parts(self):
        raise nose.SkipTest('buggy as of 2/18/14; maybe a data revision?')

        start = datetime(2010, 1, 1)
        end = datetime(2013, 1, 27)
        df = web.get_data_fred("CPIAUCSL", start, end)
        self.assertEqual(df.ix['2010-05-01'][0], 217.23)

        t = df.CPIAUCSL.values
        self.assertTrue(np.issubdtype(t.dtype, np.floating))
        self.assertEqual(t.shape, (37, ))
コード例 #9
0
    bands to a Matplotlib Figure object.

    """
      
    # load the NBER recession dates
    NBER_Dates = pd.read_csv('NBER Dates.txt')

    # for loop generates recession bands!
    for i in range(NBER_Dates.shape[0]):
        plt.axvspan(NBER_Dates['Peak'][i], NBER_Dates['Trough'][i],
                    facecolor='grey', alpha=0.5)

##### download data from FRED #####

# National Income: Compensation of Employees, Paid
COE = get_data_fred('COE', start='1947-01-01')

# Gross Domestic Product, 1 Decimal
GDP = get_data_fred('GDP', start='1947-01-01')

# combine into a DataFrame
data = pd.concat([COE, GDP], axis=1)

##### Construct measure of labor's share #####

# Divide COE by GDP
COE_share = data['COE'] / data['GDP']

##### plot the data with auto-ajusted ylim #####

# basic plot in one line of code!
コード例 #10
0
    # load the NBER recession dates
    NBER_Dates = pd.read_csv('NBER Dates.txt')

    # for loop generates recession bands!
    for i in range(NBER_Dates.shape[0]):
        plt.axvspan(NBER_Dates['Peak'][i],
                    NBER_Dates['Trough'][i],
                    facecolor='grey',
                    alpha=0.5)


##### download data from FRED #####

# Civilian unemployment rate (monthly, SA)
UNRATE_monthly = get_data_fred('UNRATE', start='1948-01-01')

# Convert to annual frequency by averaging across months
UNRATE_annual = UNRATE_monthly.resample('A', how='mean')

##### plot the historical unemployment rate #####

# basic plot in one line of code!
UNRATE_annual.plot()

# add labels, axes, title, etc
plt.xlabel("Year")
plt.ylabel("Percent")
plt.ylim(0, 10)
plt.title("Civilian unemployment rate (UNRATE), Seasonally adjusted\n" +\
          "Source: U.S. Department of Labor, BLS (via FRED)",
コード例 #11
0
import pandas as pd
import matplotlib.pyplot as plt
from pandas.io.data import get_data_fred

##### download data from FRED #####

# Real GDP per capita (2010 Dollars, annual, NSA)
USARGDPC = get_data_fred('USARGDPC', start='1960-01-01')

##### plot the data #####

# basic plot in one line of code!
ax = USARGDPC.plot(legend=False)

# add labels, axes, title, etc
ax.set_ylabel("2010 U.S. Dollars")
ax.set_yscale('log')
ax.set_ylim(8000, 64000)
ax.set_yticks([8000, 16000, 32000, 64000])
ax.set_yticklabels([8000, 16000, 32000, 64000])
ax.set_title("Real GDP per Person in the United States (USARGDPC)\nSource: U.S. Department of Labor, BLS (via FRED)", weight='bold')
ax.grid()

# load the NBER recession dates
NBER_Dates = pd.read_csv('NBER Dates.txt')

# for loop generates recession bands!
for i in range(NBER_Dates.shape[0]):
    ax.axvspan(NBER_Dates['Peak'][i], NBER_Dates['Trough'][i], facecolor='grey', alpha=0.5)
    
# save the figure and display
コード例 #12
0
import pandas as pd
import matplotlib.pyplot as plt
from pandas.io.data import get_data_fred

##### download data from FRED #####

# Consumer Price Index for All Urban Consumers: All Items (Monthly, SA)
CPIAUCSL = get_data_fred('CPIAUCSL', start='1947-01-01')

# Consumer Price Index for All Urban Consumers: All Items (Monthly, NSA)
CPIAUCNS = get_data_fred('CPIAUCNS', start='1913-01-01')

# Gross Domestic Product: Implicit Price Deflator (Quarterly, SA)
GDPDEF = get_data_fred('GDPDEF', start='1947-01-01')

##### Construct measures of inflation #####

# Inflation is measured as percentage change from one year ago
Inflation_CPIAUCSL = CPIAUCSL.pct_change(periods=12)
Inflation_CPIAUCNS = CPIAUCNS.pct_change(periods=12)
Inflation_GDPDEF = GDPDEF.pct_change(periods=4)

# Combine the three Series objects into a single DataFrame
Inflation_Measures = Inflation_CPIAUCNS
Inflation_Measures['CPIAUCSL'] = Inflation_CPIAUCSL
Inflation_Measures['GDPDEF'] = Inflation_GDPDEF

##### plot the data #####

# basic plot in one line of code!
Inflation_Measures.plot(markersize=3, style='o-', alpha=0.75)
コード例 #13
0
import pandas as pd
import matplotlib.pyplot as plt
from pandas.io.data import get_data_yahoo, get_data_fred

##### download data #####

# Download the S&P 500
SP500 = get_data_yahoo('^GSPC', start='1950-01-03', end='2012-11-30')

# Download the CPI data
CPIAUCSL = get_data_fred('CPIAUCSL', start='1950-01-01')

##### resample S&P 500 data #####

# Need S&P 500 data to be monthly...note I am taking monthly averages
monthly_avg_SP500 = SP500.resample('MS', how='mean')

# Add the CPI data as a column to the monthly DataFrame
monthly_avg_SP500['CPIAUCSL'] = CPIAUCSL

##### Convert nominal values to real values #####

# express all prices in terms of the price level in Nov. 2012...
monthly_avg_SP500['Price Deflator'] = (monthly_avg_SP500['CPIAUCSL']['2012-11-01'] / monthly_avg_SP500['CPIAUCSL'])
monthly_avg_SP500['Close (Real)'] = monthly_avg_SP500['Close'] * monthly_avg_SP500['Price Deflator']

##### Nominal S&P 500 #####

# new figure
fig = plt.figure()
コード例 #14
0
import pandas as pd
import matplotlib.pyplot as plt
from pandas.io.data import get_data_yahoo, get_data_fred

##### download data #####

# Download the S&P 500
SP500 = get_data_yahoo('^GSPC', start='1950-01-03', end='2012-11-30')

# Download the CPI data
CPIAUCSL = get_data_fred('CPIAUCSL', start='1950-01-01')

##### resample S&P 500 data #####

# Need S&P 500 data to be monthly...note I am taking monthly averages
monthly_avg_SP500 = SP500.resample('MS', how='mean')

# Add the CPI data as a column to the monthly DataFrame
monthly_avg_SP500['CPIAUCSL'] = CPIAUCSL

##### Convert nominal values to real values #####

# express all prices in terms of the price level in Nov. 2012...
monthly_avg_SP500['Price Deflator'] = (
    monthly_avg_SP500['CPIAUCSL']['2012-11-01'] /
    monthly_avg_SP500['CPIAUCSL'])
monthly_avg_SP500['Close (Real)'] = monthly_avg_SP500[
    'Close'] * monthly_avg_SP500['Price Deflator']

##### Nominal S&P 500 #####
コード例 #15
0
    bands to a Matplotlib Figure object.

    """
      
    # load the NBER recession dates
    NBER_Dates = pd.read_csv('NBER Dates.txt')

    # for loop generates recession bands!
    for i in range(NBER_Dates.shape[0]):
        plt.axvspan(NBER_Dates['Peak'][i], NBER_Dates['Trough'][i],
                    facecolor='grey', alpha=0.5)

##### download data from FRED #####

# Civilian unemployment rate (monthly, SA)
UNRATE_monthly = get_data_fred('UNRATE', start='1948-01-01')

# Convert to annual frequency by averaging across months
UNRATE_annual = UNRATE_monthly.resample('A', how='mean')

##### plot the historical unemployment rate #####

# basic plot in one line of code!
UNRATE_annual.plot()

# add labels, axes, title, etc
plt.xlabel("Year")
plt.ylabel("Percent")
plt.ylim(0, 10)
plt.title("Civilian unemployment rate (UNRATE), Seasonally adjusted\n" +\
          "Source: U.S. Department of Labor, BLS (via FRED)",