コード例 #1
0
    if events.shape[0] == 0:
        sys.stdout.write('no valid events!\n')
        continue
    timeseries = convert_events_to_timeseries(events, variables=variables)
    
    sys.stdout.write('extracting separate episodes...')
    sys.stdout.flush()

    for i in range(stays.shape[0]):
        stay_id = stays.ICUSTAY_ID.iloc[i]
        sys.stdout.write(' {}'.format(stay_id))
        sys.stdout.flush()
        intime = stays.INTIME.iloc[i]
        outtime = stays.OUTTIME.iloc[i]

        episode = get_events_for_stay(timeseries, stay_id, intime, outtime)
        if episode.shape[0] == 0:
            sys.stdout.write(' (no data!)')
            sys.stdout.flush()
            continue

        episode = add_hours_elpased_to_events(episode, intime).set_index('HOURS').sort_index(axis=0)
        episodic_data.Weight.ix[stay_id] = get_first_valid_from_timeseries(episode, 'Weight')
        episodic_data.Height.ix[stay_id] = get_first_valid_from_timeseries(episode, 'Height')
        episodic_data.ix[episodic_data.index==stay_id].to_csv(os.path.join(args.subjects_root_path, subject_dir, 'episode{}.csv'.format(i+1)), index_label='Icustay')
        columns = list(episode.columns)
        columns_sorted = sorted(columns, key=(lambda x: "" if x == "Hours" else x))
        episode = episode[columns_sorted]
        episode.to_csv(os.path.join(args.subjects_root_path, subject_dir, 'episode{}_timeseries.csv'.format(i+1)), index_label='Hours')
    sys.stdout.write(' DONE!\n')
コード例 #2
0
    sys.stdout.flush()

    for i in range(stays.shape[0]):
        stay_id = stays.ICUSTAY_ID.iloc[i]
        sys.stdout.write(' {}'.format(stay_id))
        sys.stdout.flush()
        intime = stays.INTIME.iloc[i]
        outtime = stays.OUTTIME.iloc[i]

        episode = get_events_for_stay(timeseries, stay_id, intime, outtime)
        if episode.shape[0] == 0:
            sys.stdout.write(' (no data!)')
            sys.stdout.flush()
            continue

        episode = add_hours_elpased_to_events(
            episode, intime).set_index('HOURS').sort_index(axis=0)
        episodic_data.Weight[stay_id] = get_first_valid_from_timeseries(
            episode, 'Weight')
        episodic_data.Height[stay_id] = get_first_valid_from_timeseries(
            episode, 'Height')
        episodic_data[episodic_data.index == stay_id].to_csv(
            os.path.join(args.subjects_root_path, subject_dir,
                         'episode{}.csv'.format(i + 1)),
            index_label='Icustay')
        columns = list(episode.columns)
        columns_sorted = sorted(columns,
                                key=(lambda x: "" if x == "Hours" else x))
        episode = episode[columns_sorted]
        episode.to_csv(os.path.join(args.subjects_root_path, subject_dir,
                                    'episode{}_timeseries.csv'.format(i + 1)),
                       index_label='Hours')