Example #1
0
    def test_freeze_panes(self, engine, ext):
        # see gh-15160
        expected = DataFrame([[1, 2], [3, 4]], columns=["col1", "col2"])
        expected.to_excel(self.path, "Sheet1", freeze_panes=(1, 1))

        result = pd.read_excel(self.path, index_col=0)
        tm.assert_frame_equal(result, expected)
Example #2
0
def test_fenci():

    dfs = []

    for i in range(0, 9):
        f = file('Data/ftags_{}.pkl'.format(i), 'rb')
        fdist = pickle.load(f)
        #fdist.plot(50)
        df = DataFrame(fdist.items(), columns=['关键词', '计数'])
        df = df.sort_index(by='计数', ascending=False)
        df.index = range(len(df))

        df_plt = df[:30]
        df_plt = df_plt[::-1]
        #df_plt['关键词'].apply(lambda x : x.encode('utf8'))
        print df_plt.head()
        df_plt.plot(kind='barh', x=df_plt['关键词'], title=classifies[i])

        #plt.show()

        filePath = 'Data/{}.png'.format(classifies[i])
        str_name_f = filePath.decode("utf8")
        plt.savefig(str_name_f, dpi=100)

        dfs.append((classifies[i],df))

        #print df[df[1] > 1]
        f.close()
    print 'end'

    with pd.ExcelWriter('Data/keys.xlsx') as writer:
        for key, df in dfs:
            print key
            df.to_excel(writer, sheet_name=key, index=False)
Example #3
0
def test():
    df0=DataFrame(np.arange(3))
    df0.to_excel('foo.xlsx','Data 0')
    
    df1=DataFrame(np.arange(2))
    df1.to_excel('foo.xlsx','Data 1')
    return
Example #4
0
class Excel(object):

    goal_time = 0.2
    params = ['openpyxl', 'xlsxwriter', 'xlwt']
    param_names = ['engine']

    def setup(self, engine):
        N = 2000
        C = 5
        self.df = DataFrame(np.random.randn(N, C),
                            columns=['float{}'.format(i) for i in range(C)],
                            index=date_range('20000101', periods=N, freq='H'))
        self.df['object'] = tm.makeStringIndex(N)
        self.bio_read = BytesIO()
        self.writer_read = ExcelWriter(self.bio_read, engine=engine)
        self.df.to_excel(self.writer_read, sheet_name='Sheet1')
        self.writer_read.save()
        self.bio_read.seek(0)

        self.bio_write = BytesIO()
        self.bio_write.seek(0)
        self.writer_write = ExcelWriter(self.bio_write, engine=engine)

    def time_read_excel(self, engine):
        read_excel(self.bio_read)

    def time_write_excel(self, engine):
        self.df.to_excel(self.writer_write, sheet_name='Sheet1')
        self.writer_write.save()
Example #5
0
def LaGouSpiderWithKeyWord(position, city):
    # 获取总共页数
    pageCount = SearchPageCount(position, city)
    if pageCount == 0:
        print('抱歉!在您搜索的城市中没有您要找的职位')
        return

    totaldata = DataFrame().T
    for i in range(0, pageCount):
        url = 'http://www.lagou.com/jobs/positionAjax.json?'
        params = {'city': city, 'kd': position, 'pn': i+1}
        url += parse.urlencode(params)
        data = request.urlopen(url).read()
    #     读取Json数据
        jsondata = json.loads(str(data, encoding='utf-8', errors='ignore'))['content']['result']
        for t in list(range(len(jsondata))):
            jsondata[t]['companyLabelListTotal'] = '-'.join(jsondata[t]['companyLabelList'])
            jsondata[t].pop('companyLabelList')
            if t == 0:
                rdata = DataFrame(Series(data=jsondata[t])).T
            else:
                rdata = pd.concat([rdata,DataFrame(Series(data=jsondata[t])).T])
        totaldata = pd.concat([totaldata, rdata])
        print('正在解析第{0}页...'.format(i+1))
    totaldata.to_excel('lagou.xls', sheet_name='sheet1')
Example #6
0
    def test_to_excel_unicode_filename(self):
        _skip_if_no_excelsuite()

        for ext in ["xls", "xlsx"]:
            filename = u"\u0192u." + ext

            try:
                f = open(filename, "wb")
            except UnicodeEncodeError:
                raise nose.SkipTest("no unicode file names on this system")
            else:
                f.close()

            df = DataFrame(
                [[0.123456, 0.234567, 0.567567], [12.32112, 123123.2, 321321.2]],
                index=["A", "B"],
                columns=["X", "Y", "Z"],
            )

            with ensure_clean(filename) as filename:
                df.to_excel(filename, "test1", float_format="%.2f")

                reader = ExcelFile(filename)
                rs = reader.parse("test1", index_col=None)
                xp = DataFrame(
                    [[0.12, 0.23, 0.57], [12.32, 123123.20, 321321.20]], index=["A", "B"], columns=["X", "Y", "Z"]
                )
                tm.assert_frame_equal(rs, xp)
Example #7
0
def plot_stuff():
    pd_list = {}
    compare_tl = []
    compare_tl_head = []
    for vars in list_communities():
        for var in vars:
            pd_list.update({var.split("/")[-1].split(".")[0]: DataFrame(
                sorted(read_csv(var)[["Name", "G"]].values, key=lambda x: x[0], reverse=True))})

        N = len(pd_list.keys())  # Find number of elements
        stats = np.zeros((N, N))  # Create a 2-D Array to hold the stats
        keys = sorted(pd_list, reverse=True)  # Find data sets (Sort alphabetically, backwards)
        for idx, key in enumerate(keys):  # Populate 2-D array
            for i, val in enumerate(pd_list[key][1].values):
                if not i == idx:  # Ensure self values are set to zero
                    stats[i, idx] = val

        stats = DataFrame(stats, columns=keys, index=keys)
        # stats["Mean"] = stats.median(axis=0)
        # set_trace()
        stats["Mean"] = find_mean(stats)
        stats["Std"] = find_std(stats)
        stats = stats.sort_values(by="Mean", axis=0, ascending=False, inplace=False)
        print(tabulate(stats, showindex=True, headers=stats.columns, tablefmt="fancy_grid"))
        print("\n")
        save_path = os.path.abspath("/".join(var.split("/")[:-2]))
        method = var.split("/")[-2]+".xlsx"
        stats.to_excel(os.path.join(save_path, method))
        compare_tl.append(stats.sort_index(inplace=False)["Mean"].values.tolist())
        compare_tl_head.append(method)
    # set_trace()
    compare_tl= DataFrame(np.array(compare_tl).T, columns=compare_tl_head, index=stats.index.sort_values())
    save_path_2 = os.path.join(os.path.abspath("/".join(var.split("/")[:-3])), os.path.abspath("".join(var.split("/")[-3]))+".xlsx")
    compare_tl.to_excel(save_path_2)
Example #8
0
    def test_importItems(self):
        wrongFields = [{"a": "What is your gender?",
                      "b": 0.7,
                      "c": "radio",
                      "d": 0.3,
                      "e": "Male, Female, Other",
                      "f": 'vert'}]

        wrongOptions = [{"questionText": "What is your gender?",
                      "questionWidth": 0.7,
                      "type": "radio",
                      "responseWidth": 0.3,
                      "options": "Other",
                      "layout": 'vert',
                      "index": 0}]

        df = DataFrame(self.questions)
        df.to_excel(fileName_xlsx, index=False)
        df.to_csv(fileName_csv, index=False)

        # Check wrong field error
        with pytest.raises(NameError):
            self.survey = Form(self.win, items=wrongFields, size=(1.0, 0.3), pos=(0.0, 0.0), autoLog=False)

        # Check options for list of dicts
        with pytest.raises(ValueError):
            self.survey = Form(self.win, items=wrongOptions, size=(1.0, 0.3), pos=(0.0, 0.0), autoLog=False)

        # Check csv
        self.survey = Form(self.win, items=fileName_csv,
                           size=(1.0, 0.3), pos=(0.0, 0.0), autoLog=False)
        # Check Excel
        self.survey = Form(self.win, items=fileName_xlsx,
                           size=(1.0, 0.3), pos=(0.0, 0.0), randomize=False, autoLog=False)
Example #9
0
    def test_to_excel_unicode_filename(self):
        _skip_if_no_xlrd()
        ext = self.ext
        filename = u('\u0192u.') + ext

        try:
            f = open(filename, 'wb')
        except UnicodeEncodeError:
            raise nose.SkipTest('no unicode file names on this system')
        else:
            f.close()

        df = DataFrame([[0.123456, 0.234567, 0.567567],
                        [12.32112, 123123.2, 321321.2]],
                        index=['A', 'B'], columns=['X', 'Y', 'Z'])

        with ensure_clean(filename) as filename:
            df.to_excel(filename, 'test1', float_format='%.2f')

            reader = ExcelFile(filename)
            rs = reader.parse('test1', index_col=None)
            xp = DataFrame([[0.12, 0.23, 0.57],
                            [12.32, 123123.20, 321321.20]],
                            index=['A', 'B'], columns=['X', 'Y', 'Z'])
            tm.assert_frame_equal(rs, xp)
Example #10
0
def write_to_excel(data):
    # Model the data as such:
    #     List [
    #       0    Principle Account,
    #       1    Component Principle Account,
    #       2    Endowment Name,
    #       3    Long Term, 
    #       4    Temp
    #       5    Misc
    #          ]

    variables = [[],[],[],[],[],[],[],[]]
    col_names = ['Endowment Name', 'Component Principle Account', 'Principle Account', 'Long Term', 'Temp', 'Misc', 'Misc2', 'Misc2']
    
    
    for i in data:
        for x, j in enumerate(i):
            if x > len(variables):
                variables.append([])
            variables[x].append(j)
    

    df = DataFrame(variables)
    
    df = df.T
    df.columns = col_names
    df.to_excel("test.xlsx", sheet_name="Data", index=False)
Example #11
0
 def test_excelfile_fspath(self):
     with tm.ensure_clean('foo.xlsx') as path:
         df = DataFrame({"A": [1, 2]})
         df.to_excel(path)
         xl = ExcelFile(path)
         result = os.fspath(xl)
         assert result == path
Example #12
0
    def to_excel(self, outfile, units = ''):
        """Export timing info to excel file.
        Returns location of exported file.
        Automatically timestamps filename in format:
            yyyy-mm-dd-hh:mm:ss

        Parameters
        ----------
            excel_file:
                the name of the file to export from. 
                e.g. file.xls
            units:
                the units to export the data in; one of ['min', 'sec']
        """
        if self.data == None or self.units == None:
            raise DataError('Cannot export; no data!')
        if units == '':
            units = self.units
        try:
            filename = timestamp(outfile)
            df = DataFrame(self.get_data(units), columns = ['frame', 'start time', 'duration', 'stop time'])
            df.to_excel(filename, sheet_name = 'Sheet1', index = False)
            return filename
        except IOError:
            print 'Whoops'
 def to_excel(self, puts_path='/tmp/puts.xls', calls_path='/tmp/calls.xls'):
     dataframe = DataFrame(data=self.puts)
     dataframe.to_excel(puts_path)
     print 'Puts saved at %s' % (puts_path)
     dataframe = DataFrame(data=self.calls)
     dataframe.to_excel(calls_path)
     print 'Calls saved at %s' % (calls_path)
Example #14
0
	def OnExit(self):
		#Does all of the initialising and saves the flow data

		intersectionFlowRates = {}
		#Loop through all of the junctions
		for i in self._intersectionFlow:
			#Loop through all of the intervals
			localFlowRates = []
			for x in range(0,len(self._intersectionFlow[i])):
				localFlowRates.append(3600*self._intersectionFlow[i][x]/constants.CONST_MEASUREMENT_INTERVAL)
			intersectionFlowRates[i] = localFlowRates

		intersectionFlowRates['Time'] = range(0,len(intersectionFlowRates[i])*constants.CONST_MEASUREMENT_INTERVAL,constants.CONST_MEASUREMENT_INTERVAL)
		df = DataFrame(intersectionFlowRates)

		folderName = constants.CONST_EXPERIMENT_NAME
		newFolderurl = os.path.abspath(os.path.join(os.getcwd(),os.pardir)) + '\\MyProgram\\Tests\\Experiments\\' + folderName
		counter = 0
		while os.path.exists(newFolderurl):
			newFolderurl = os.path.abspath(os.path.join(os.getcwd(),os.pardir)) + '\\MyProgram\\Tests\\Experiments\\' + folderName + '_' + str(counter)
			counter +=1

		os.makedirs(newFolderurl)
		df.to_excel(newFolderurl + '\\' + constants.CONST_FLOW_FILE_NAME, sheet_name='sheet1', index=False)


		#Saves the settings file as well in the same folder
		shutil.copyfile(self._configFile, newFolderurl  + '\\' + self._configFile.split("\\")[-1])
def chart_voice_format():
	voices = get_voice_list()
	formats = get_format_list()
	data = []
	for voice in voices:
		v_chart = []
		for format in formats:
			play = 0.0
			buy = 0.0
			for event in database.db.events.find({'format':format,'voices':voice}):
				if event['event'] == 'play':
					play += 1
				elif event['event'] == 'purchase':
					buy +=1
			v_chart.append(play)
			v_chart.append(buy)
		data.append(v_chart)
	f_list = []
	k_list = []
	for format in get_format_list():
		f_list.append(format)
		f_list.append(format)
		k_list.append('play')
		k_list.append('buy')
	col = pd.MultiIndex.from_arrays([f_list,k_list],names=['format','type'])

	chart = DataFrame(data,columns=col,index=get_voice_list())
	chart.to_excel('files/voice_format_analysis.xls')
	return chart
def chart_templates():
	index = get_template_list()
	index = list(set(index))

	t_play = []
	t_buy = []
	t_producer = []
	index.sort()
	for template in index:
		buy = 0.0
		play = 0.0
		producer = db.templates.find_one({'name':template})['producer']
		for event in db.events.find({'template':template}):
			producer = event['producer']
			if event['event'] == 'play':
				play +=1
			elif event['event'] == 'purchase':
				buy +=1
		t_producer .append(producer)
		t_play.append(play)
		t_buy.append(buy)
	data = {
		'play':t_play,
		'buy':t_buy,
		'producer':t_producer
	}

	chart = DataFrame(data,index=index,columns=['producer','play','buy'])
	chart['b2p_percent'] = (chart.buy/chart.play)*100
	chart.sort_index()
	chart.to_excel('templates_analysis.xls')
Example #17
0
 def generate_excel(self):
   data = self.generate_data()
   if data:
     dataframe = DataFrame(data)
     dataframe.to_excel('data.xlsx', sheet_name='sheet1', index=False)
     print "Generated Excel Sheet with name data.xlsx"
   else:
     print "No data found"
Example #18
0
 def test_excel_multiindex_index(self, ext):
     # MultiIndex as index works so assert no error #9794
     cols = MultiIndex.from_tuples([('site', ''),
                                    ('2014', 'height'),
                                    ('2014', 'weight')])
     df = DataFrame(np.random.randn(3, 10), index=cols)
     with ensure_clean(ext) as path:
         df.to_excel(path, index=False)
Example #19
0
    def test_inf_roundtrip(self, engine, ext):
        df = DataFrame([(1, np.inf), (2, 3), (5, -np.inf)])
        df.to_excel(self.path, "test1")

        reader = ExcelFile(self.path)
        recons = pd.read_excel(reader, "test1", index_col=0)

        tm.assert_frame_equal(df, recons)
Example #20
0
    def test_inf_roundtrip(self):
        _skip_if_no_xlrd()

        frame = DataFrame([(1, np.inf), (2, 3), (5, -np.inf)])
        with ensure_clean(self.ext) as path:
            frame.to_excel(path, 'test1')
            reader = ExcelFile(path)
            recons = reader.parse('test1')
            tm.assert_frame_equal(frame, recons)
Example #21
0
def produce_imbalance_evolution(simulation=simulation, year_min = 1996):
    
    arrays=arange(year_min, year_min+60)
    record = DataFrame(index=arrays)
    record['déséquilibre'] = NaN
    record['déséquilibre_alt'] = NaN
    
#     for year in range(year_min, year_min+60):
#         print year
#         #On tente de tronquer la df au fil du temps
#         try:
#             simulation.aggregate_pv = simulation.aggregate_pv.drop(labels=year-1, level='year')
#             simulation.aggregate_pv_alt = simulation.aggregate_pv_alt.drop(labels=year-1, level='year')
#         except:
#             print 'except path'
#             pass
#         simulation.aggregate_pv = AccountingCohorts(simulation.aggregate_pv)
#         simulation.aggregate_pv_alt = AccountingCohorts(simulation.aggregate_pv_alt)
#         
#         ratio_base = simulation.compute_gen_imbalance(typ='net_transfers')
#         ratio_alt = simulation.compute_gen_imbalance(typ='net_transfers', default=False)
#         record.loc[year, "déséquilibre"] = ratio_base
#         record.loc[year, 'déséquilibre_alt'] = ratio_alt
#     print record.head(30).to_string()
#     record.to_excel(xls+'imbalance_flux.xlsx', 'flux de déséquilibre')

    for year in range(year_min, year_min+60):
        print year
        #On tente de tronquer la df au fil du temps
        try:
            simulation.population = simulation.population.drop(labels=year-1, level='year')
            simulation.population_alt = simulation.population_alt.drop(labels=year-1, level='year')
        except:
            print 'except path'
            pass
        
        taxes_list = ['tva', 'tipp', 'cot', 'irpp', 'impot', 'property']
        payments_list = ['chomage', 'retraite', 'revsoc', 'maladie', 'educ']
        
        simulation.create_cohorts()
        simulation.create_cohorts(default=False)

        simulation.cohorts.compute_net_transfers(name = 'net_transfers', taxes_list = taxes_list, payments_list = payments_list)
        simulation.create_present_values('net_transfers', default=True)
        
        simulation.cohorts_alt.loc[[x>=2027 for x in simulation.cohorts_alt.index.get_level_values(2)], 'retraite'] *= (1-0.1)
        simulation.cohorts_alt.compute_net_transfers(name = 'net_transfers', taxes_list = taxes_list, payments_list = payments_list)
        simulation.create_present_values('net_transfers', default=False)

#                     imbalance = simulation.compute_gen_imbalance(typ='net_transfers')
        imbalance = simulation.compute_gen_imbalance(typ='net_transfers')
        imbalance_alt = simulation.compute_gen_imbalance(typ='net_transfers', default=False)
       
        
        record.loc[year, "déséquilibre"] = imbalance
        record.loc[year, 'déséquilibre_alt'] = imbalance_alt
    record.to_excel(xls+'\imbalance_flux_agre.xlsx', 'flux de déséquilibre')
Example #22
0
    def test_float_types(self, engine, ext, np_type):
        # Test np.float values read come back as float.
        df = DataFrame(np.random.random_sample(10), dtype=np_type)
        df.to_excel(self.path, "test1")

        reader = ExcelFile(self.path)
        recons = pd.read_excel(reader, "test1", index_col=0).astype(np_type)

        tm.assert_frame_equal(df, recons, check_dtype=False)
def inicio(base,x=1, p=5100):
    tipo=[]
    adi_n=[]
    origem=[]      
    relator=[]
    dispositivo=[]
    entrada=[]
    distribuicao=[]
    requerente=[]
    requerido=[]
    emenda=[]
    requerentep=[]
    adi_error=[]
    fundamenta=[]
    rliminar=[]
    dpliminar=[]    
    rfinal=[]
    dfinal=[]   
    dmliminar=[]
    dmfinal=[]
    incidentes=[] 
    ementa=[]
    index=[]
    for n in range(x, p):
         list=stfWorm(base, n)
         if (list==False):
             continue
         tipo.append(base)
         adi_n.append(list[0])
         origem.append(list[1])
         relator.append(list[2])
         entrada.append(list[3])
         distribuicao.append(list[4])
         requerente.append(list[5])
         requerido.append(list[6])
         dispositivo.append(list[7])
         fundamenta.append(list[8])
         rliminar.append(list[9])
         dpliminar.append(list[10])
         rfinal.append(list[11])
         dfinal.append(list[12])
         dmliminar.append(list[13])
         dmfinal.append(list[14])
         incidentes.append(list[15]) 
         ementa.append(list[16])
         index.append(list[17])
         print(list[7])
         if  list[7]!=None and ( ('Emenda' or 'emenda' or 'EMENDA') in list[7] ) :
             emenda.append(1)
         else:
             emenda.append(0)
         requerentep.append(requerente_p(list[5]))
         print(n)
    print(adi_n, origem, relator, entrada, distribuicao, requerente, requerido, dispositivo, emenda, requerentep)   
    df = DataFrame({'01_tipo': tipo, '02_numero': adi_n, '03_Origem': origem, '04_relator': relator, '05_data_entrada': entrada, '06_distribuicao': distribuicao, '07_requerente': requerente, '08_requerido': requerido, '09_dispositivo_legal': dispositivo, '10_emenda': emenda, '11_requerente_p': requerentep, '12_fundamentacao': fundamenta, '13_resultadoliminar': rliminar, '14_decisao_plenaria_liminar': dpliminar, '15_resultado_final': rfinal, '16_decisao_final': dfinal, '17_decisao_monocratica_liminar': dmliminar, '18_decisao_monocratica_final':dmfinal, '19_incidentes':incidentes, '20_ementa':ementa, '21_indexacao':index})
    print(df)
    df.to_excel('teste1.xlsx', sheet_name='sheet1', index=False)
def study_GetBehILSStatus(SubjectsSummary,study,studydata,writer):
#    for i in range(0,len(SubjectsSummary),1):
#        print "%d %s"%(i,SubjectsSummary[i].Subject.subid)
    conn_qc = studydata.db_connection    
    Measures = ['iLS6_propHT']
    full_list = []
    # create the column names for the output spreadsheet
    ColumnNames = []
    ColumnNames.append('subid')

    for meas in Measures:
        ColumnNames.append(meas)
            
    for j in range(0,len(SubjectsSummary),1):
        one_list = []
        one_list.append(SubjectsSummary[j].Subject.subid)
        # search through the COlumn Name list 
        for index in range(1,len(ColumnNames),1):
            task = ColumnNames[index]
            sqlcommand = "SELECT subid"
            sqlcommand="%s,%s"%(sqlcommand,task)
            sqlcommand=sqlcommand+" FROM cnsdivdb.iLSBehav where subid='%s'"%(SubjectsSummary[j].Subject.subid)    
                
           # print sqlcommand
            try:
                # ret is the number of rows returned
                ret = conn_qc.cur.execute(sqlcommand)
                if ret is 0:
                    one_list.append(-9999)
                elif ret is 1:
                    row_dict = conn_qc.cur.fetchall()
                    value = row_dict[0][ColumnNames[index]]
                    if value > 0:
                        one_list.append(1)
                    else:
                        one_list.append(0)
                elif ret > 1:
                    MultipleRowFlag = True
                    for row_dict in conn_qc.cur.fetchall():   
                        # value from first row
                        if MultipleRowFlag:
                            value = row_dict[ColumnNames[index]]
                            if value > 0:
                                one_list.append(1)
                                MultipleRowFlag = False
                    if MultipleRowFlag:
                        # if this flag is still true then there are multiple
                        # rows in the dB with no data in them
                        one_list.append(-9999)
                                
            except:
                one_list.append(-9999)
        full_list.append(one_list)
 
    df=DataFrame(full_list, columns=ColumnNames)
    df.to_excel(writer,sheet_name="BehavioralData",index=False)
    return SubjectsSummary,df
def _write_columns_to_excel(c1, c2, c3):
    weekday_list = _build_date_list_weeks()
    padded_c2, padded_c3 = _pad_other_lists(weekday_list, c1, c2, c3)

    dtstr = datetime.now().strftime("%Y%m%d-%H%M%S")
    file_name = 'output/work_log_{}.xlsx'.format(dtstr)
    df = DataFrame({'Date': weekday_list, 'Ticket Name': padded_c2, 'Ticket Data': padded_c3})
    # print(df)
    df.to_excel(file_name, sheet_name='sheet1', index=False)
Example #26
0
 def test_excel_raise_error_on_multiindex_columns_and_no_index(
         self, ext):
     # MultiIndex as columns is not yet implemented 9794
     cols = MultiIndex.from_tuples([('site', ''),
                                    ('2014', 'height'),
                                    ('2014', 'weight')])
     df = DataFrame(np.random.randn(10, 3), columns=cols)
     with pytest.raises(NotImplementedError):
         with ensure_clean(ext) as path:
             df.to_excel(path, index=False)
Example #27
0
    def test_swapped_columns(self, engine, ext):
        # Test for issue #5427.
        write_frame = DataFrame({'A': [1, 1, 1],
                                 'B': [2, 2, 2]})
        write_frame.to_excel(self.path, 'test1', columns=['B', 'A'])

        read_frame = pd.read_excel(self.path, 'test1', header=0)

        tm.assert_series_equal(write_frame['A'], read_frame['A'])
        tm.assert_series_equal(write_frame['B'], read_frame['B'])
def study_GetStatsStatus(SubjectsSummary,study,writer):
    spmVer = 'spm8'
    HeaderFlag = True
    # cycle over subjects
    # this will hold data for all subjects
    full_list = []
    for j in range(0,len(SubjectsSummary),1):
        Str = SubjectsSummary[j].Subject.subid
        # this will hold data for ONE subject  
        one_list = []
        one_list.append(SubjectsSummary[j].Subject.subid)
        # create the column names ONCE
        if HeaderFlag is True:
            ColumnNames = []
            ColumnNames.append('subid')
            for index in SubjectsSummary[0].TaskList:
                ColumnNames.append(SubjectsSummary[j].Scans[index]['SeriesName'])
            ColumnNames.append("AllStatsProcessed")
        count = 0    
        for index in SubjectsSummary[0].TaskList:
            task = SubjectsSummary[j].Scans[index]['SeriesName']
            # strip run numbers from the task name
            task=task.split('_r')[0]
            
            foundStatsFlag = False
            for visit in SubjectsSummary[j].Subject.visitlist:
                filePath=os.path.join(visit.path,'fmriStats',task,spmVer,'spmT_0001.img')
                if os.path.exists(filePath):
                    foundStatsFlag = True
                        
            if foundStatsFlag is True:
                one_list.append(1)
                count = count + 1
            else:
                one_list.append(0)
                count = count + 0
            # append the one subject list to the full list
        if count is len(SubjectsSummary[0].TaskList):
            one_list.append("TRUE")
        else:
            one_list.append("FALSE")
        full_list.append(one_list)
        print Str
    # now create the data frame for pandas
    df=DataFrame(full_list, columns=ColumnNames)
    # format it for Excel and write it to a file
    df.to_excel(writer,sheet_name="StatsData",index=False)
    # write out codes
    codes = []
    codes.append([0,'stats NOT done'])
    codes.append([1,'stats done'])
    CodeColNames = ['code','description']
    df_Notes=DataFrame(codes,columns=CodeColNames)
    df_Notes.to_excel(writer,sheet_name="StatsData",index=False)
    return df
Example #29
0
    def test_float_types(self):
        _skip_if_no_xlrd()

        for np_type in (np.float16, np.float32, np.float64):
            with ensure_clean(self.ext) as path:
                # Test np.float values read come back as float.
                frame = DataFrame(np.random.random_sample(10), dtype=np_type)
                frame.to_excel(path, 'test1')
                reader = ExcelFile(path)
                recons = reader.parse('test1').astype(np_type)
                tm.assert_frame_equal(frame, recons, check_dtype=False)
Example #30
0
    def test_excel_roundtrip_bool(self):
        _skip_if_no_openpyxl()

        # Test roundtrip np.bool8, does not seem to work for xls
        path = "__tmp_excel_roundtrip_bool__.xlsx"
        frame = DataFrame(np.random.randn(10, 2)) >= 0
        frame.to_excel(path, "test1")
        reader = ExcelFile(path)
        recons = reader.parse("test1")
        tm.assert_frame_equal(frame, recons)
        os.remove(path)