pandas 如何在Jupyter中以字符串的形式而不是以表的形式显示这些导入的数据?

zyfwsgd6  于 2023-06-20  发布在  其他
关注(0)|答案(1)|浏览(117)

数据(马里布海滩,商业和长滩)从Excel中加载弹出窗口。我使用下面的代码,当我打开任何弹出窗口时,它以表格的形式显示(图1)。我想把它做成Spring的形式(例如:图2)。你能提示我如何做这件事吗?

import folium
import pandas as pd
import io

data = '''
Name A1 A2 A3 LAT LON
"Malibu Beach" 0.63 0.55 0.95 34.03194 -118.698387
'Commerce' 0.17 0.45 0.25 34.00031 -118.159770
"Long Beach" 0.19 0.21 0.09 33.77171 -118.181310'''

data = pd.read_csv(io.StringIO(data), delim_whitespace=True)

map = folium.Map([data.LAT.mean(),
data.LON.mean()],zoom_control=True,zoom_start = 9,scrollWheelZoom=True,tiles = "Stamen Terrain")

for i in range(len(data)):
html = data.loc[i,['Name','A1','A2','A3']].to_frame().T.to_html(
  classes="table table-striped table-hover table-condensed table-responsive")
popup = folium.Popup(html, max_width=500)
folium.Marker([data.iloc[i]['LAT'], data.iloc[i]['LON']],popup =folium.Popup(html, max_width=500),icon=folium.Icon(icon='cloud',color='darkblue')).add_to(map)

map

picture 1
picture 2

cgvd09ve

cgvd09ve1#

不要使用.T转置数据:

data = pd.read_csv(io.StringIO(data), delim_whitespace=True)

map = folium.Map([data.LAT.mean(),
data.LON.mean()],zoom_control=True,zoom_start = 9,scrollWheelZoom=True,tiles = "Stamen Terrain")

for i in range(len(data)):
   html = data.loc[i,['Name','A1','A2','A3']].to_frame().to_html(header=False, classes="table table-condensed table-responsive", border=0)
   popup = folium.Popup(html, max_width=500)
   folium.Marker([data.iloc[i]['LAT'], data.iloc[i]['LON']],popup =folium.Popup(html, max_width=500),icon=folium.Icon(icon='cloud',color='darkblue')).add_to(map)

map

相关问题