def test_deferred_with_groupby():

    # GH 12486
    # support deferred resample ops with groupby
    data = [['2010-01-01', 'A', 2], ['2010-01-02', 'A', 3],
            ['2010-01-05', 'A', 8], ['2010-01-10', 'A', 7],
            ['2010-01-13', 'A', 3], ['2010-01-01', 'B', 5],
            ['2010-01-03', 'B', 2], ['2010-01-04', 'B', 1],
            ['2010-01-11', 'B', 7], ['2010-01-14', 'B', 3]]

    df = DataFrame(data, columns=['date', 'id', 'score'])
    df.date = pd.to_datetime(df.date)

    def f(x):
        return x.set_index('date').resample('D').asfreq()
    expected = df.groupby('id').apply(f)
    result = df.set_index('date').groupby('id').resample('D').asfreq()
    assert_frame_equal(result, expected)

    df = DataFrame({'date': pd.date_range(start='2016-01-01',
                                          periods=4,
                                          freq='W'),
                    'group': [1, 1, 2, 2],
                    'val': [5, 6, 7, 8]}).set_index('date')

    def f(x):
        return x.resample('1D').ffill()
    expected = df.groupby('group').apply(f)
    result = df.groupby('group').resample('1D').ffill()
    assert_frame_equal(result, expected)
# <editor-fold desc="Description">
frmAllBus = frmTrnBus.append(frmTestBus)
frmAllChk = frmTrnChk.append(frmTestChk)

#get rid of unused
del frmTrnChk;del frmTestChk;del frmTrnBus;del frmTestBus
# </editor-fold>

#-------------------
#Data Cleaning
#-------------------

# <editor-fold desc="Description">
#convert any data types
#Review Date - unicode data into datetime
frmTrnRev.date = [datetime.strptime(date, '%Y-%m-%d') for date in frmTrnRev.date]
frmTestRev.date = [datetime.strptime(date, '%Y-%m-%d') for date in frmTestRev.date]

#Flatten any nested columns
#business categories
#user votes
frmTrnUser['votes_cool'] = [rec['cool'] for rec in frmTrnUser.votes]
frmTrnUser['votes_funny'] = [rec['funny'] for rec in frmTrnUser.votes]
frmTrnUser['votes_useful'] = [rec['useful'] for rec in frmTrnUser.votes]

#review votes
frmTrnRev['votes_cool'] = [rec['cool'] for rec in frmTrnRev.votes]
frmTrnRev['votes_funny'] = [rec['funny'] for rec in frmTrnRev.votes]
frmTrnRev['votes_useful'] = [rec['useful'] for rec in frmTrnRev.votes]

#Other misc cleaning
Example #3
0
"""
from xml.etree.ElementTree import parse
from pandas import DataFrame, Series

doc = parse('generated-data\patient-613876.fhir-bundle.xml')

root = doc.getroot()

"""for item in doc.iterfind('feed/'):
    title = item.findtext('title')
    print title
    print doc
"""
#found = [element for element in doc.iter() if element.text == 'A']
#encounters = doc.findall('{http://hl7.org/fhir}Encounter')
#print encounters

encounter_dates = []
for encounter in doc.findall('.//{http://hl7.org/fhir}Encounter'):
    period = encounter.find('{http://hl7.org/fhir}period')
    start_date = period.find('{http://hl7.org/fhir}start')
    encounter_dates.append(start_date.get('value'))

#print len(encounter_dates)

enc_dates = DataFrame(encounter_dates, columns= ['date'])
enc_dates.date = enc_dates.date.astype("datetime64")
print enc_dates

enc_dates.groupby([enc_dates.date.dt.week, enc_dates.date.dt.year]).count().plot(kind="barh")