我有输出文本,这是形式的
title1 URL1
title1 URL2
title1 URL3
title1 URL4
title1 URL5
title1 URL6
想要用熊猫把它显示成桌子
title1 url1
粉末冶金url2
粉末冶金url3
粉末冶金url4
粉末冶金url5
粉末冶金url6
发布于 2018-11-05 07:18:24
IIUC:以下是你能做的:
from pandas.compat import StringIO
import pandas as pd
import numpy as np
text = '''title url
title1 URL1
title1 URL2
title1 URL3
title1 URL4
title1 URL5
title1 URL6'''
df = pd.read_csv(StringIO(text), sep='\s+')
#Drop duplicates by keeping first
df['title'] = df['title'].drop_duplicates(keep='first')
#Replace nan with white space
df = df.replace(np.nan, ' ', regex=True)
df.to_html('test.html')您将得到如下输出:

https://stackoverflow.com/questions/53148781
复制相似问题