HTML code to display broken data_frame on one html page using python

I am new to html / css and ask a question about the data displayed in html format. I have a long list that I want to split and show in html format as two separate columns. For example, instead of:

Col1 Col2 1 a 2 a 3 a 4 a 5 b 6 b 7 b 8 b 

I want to see the text as

 Col1 Col2 Col1 Col2 1 a 5 b 2 a 6 b 3 a 7 b 4 a 8 b 

What should my html / css code look like to have this data above in a split table?

For the first output, seeing all the data in 2 columns in one table, I use python code:

 start = '''<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta></head> ''' font_size = '14pt' style = '''<style media="screen" type="text/css"> table.table1 { border-collapse: collapse; width: 20%; font-size: '''+font_size+'''; } td { text-align: left; border: 1px solid #ccc; } th { text-align: left; border: 1px solid #ccc; background-color: #072FB1; } </style> ''' title = '''<div align="center"></br><font size = "24"><strong>'''+title+'''</strong></font></br></br></</div>''' df_data1 = df_data[1:10] data = df_data1.to_html( index = False, na_rep ='' ) data = data.replace('None', '') style_headers = 'background-color: #072FB1; color: #ffffff;' style_status_new ='background-color: #587EF8; color: #ffffff;font-weight:bold' style_first_col = 'font-weight:bold;' total = 'TOTAL' soup = bs4.BeautifulSoup(data) soup.thead.tr.attrs['style'] = style_headers html = start+lentos+style+'''<body bgcolor="#FFFFFF">'''+title+time+unicode.join(u'\n',map(unicode,soup))+finish try: with open(dir_files+'engines_tv_html.html', 'w') as file: file.write(html.encode('UTF-8')) except Exception, e: log_error() 

Where in df_data[1:10] I share my data to separate data_frames. So the question is to see the broken data_frame (one table on the left and another on the right) on one html page

+4
source share
2 answers

Since your data is managed by pandas.DataFrame , I suggest you try building a table using pandas .

 pd.merge(left=df_data[0:4], left_index=True, right=df_data[4:8].reset_index(drop=True), right_index=True, suffixes=['_left','_right'], how='outer') Col1_left Col2_left Col1_right Col2_right 0 1 a 5 b 1 2 a 6 b 2 3 a 7 b 3 4 a 8 b 
+1
source

Found a solution! When we read data from a data_frame, we can first translate it by the desired amount, and then we need to delete the previous indexing, and then we can concatenate this data:

  pirmas_m = df_data[0:30].reset_index(drop=True) antras_m = df_data[30:60].reset_index(drop=True) trecias_m = df_data[60:90].reset_index(drop=True) ketvirtas_m = df_data[90:120].reset_index(drop=True) opa = pd.concat( [pirmas_m, antras_m, trecias_m, ketvirtas_m], axis=1 ) 
0
source

All Articles