悬停模板='大陆:%{df['大陆']}
'+'国家:%{df['国家']}
'+'gdpPercap:%{x:,.4f}
'+'lifeExp:%{y} '+''
我正在尝试使用hovertemplate 来自定义悬停信息。但是我无法让它显示我想要的内容。我正在让 x 和 y 正常工作。但我不知道如何将其他字段添加到悬停模板中。任何帮助,将不胜感激。
import numpy as np
df = df[df['year'] == 1952]
customdata = np.stack((df['continent'], df['country']), axis=-1)
fig = go.Figure()
for i in df['continent'].unique():
df_by_continent = df[df['continent'] == i]
fig.add_trace(go.Scatter(x=df_by_continent['gdpPercap'],
y=df_by_continent['lifeExp'],
mode='markers',
opacity=.7,
marker = {'size':15},
name=i,
hovertemplate=
'Continent: %{customdata[0]}<br>'+
'Country: %{customdata[1]}<br>'+
'gdpPercap: %{x:,.4f} <br>'+
'lifeExp: %{y}'+
'<extra></extra>',
))
fig.update_layout(title="My Plot",
xaxis={'title':'GDP Per Cap',
'type':'log'},
yaxis={'title':'Life Expectancy'},
)
fig.show()
Run Code Online (Sandbox Code Playgroud)
更新了更多代码。第一个答案仅返回 comdata 的文本值不起作用。
我有一个数据框:
Name Hours_Worked
1 James 3
2 Sam 2.5
3 Billy T
4 Sarah A
5 Felix 5
Run Code Online (Sandbox Code Playgroud)
第一,如何计算具有非数字值的行数?
第二,如何过滤以识别包含非数字值的行?
我有一个数据框:
Name Section
1 James P3
2 Sam 2.5C
3 Billy T35
4 Sarah A85
5 Felix 5I
Run Code Online (Sandbox Code Playgroud)
如何将数值拆分为名为 Section_Number 的单独列,并将字母值拆分为 Section_Letter。预期结果
Name Section Section_Number Section_Letter
1 James P3 3 P
2 Sam 2.5C 2.5 C
3 Billy T35 35 T
4 Sarah A85 85 A
5 Felix 5L 5 L
Run Code Online (Sandbox Code Playgroud) 我有一个 1000 万行的表
我有重复的行,并且我开发了一个集中了几列的列。这个创建的列应该是唯一的。
这就是我所拥有的
列1 列2 列3 ... 列50 1 吉姆·雷德 1jimred 1 吉姆·雷德 1jimred 2 山姆蓝 1samblue 3 狐狸粉红 3foxpink
我想要的是
列1 列2 列3 ... 列50 1 吉姆·雷德 1jimred 2 山姆蓝 1samblue 3 狐狸粉红 3foxpink
我想编写一个程序来删除 col50 中找到的重复行并保留所有其他列。
不过,我认为 1000 万行中有 900 万行是唯一的,因此我无法将结果存储在内存中。
有没有办法做到这一点?