我有两列字符串.我想将它们组合起来并忽略nan值.这样:
ColA, Colb, ColA+ColB
str str strstr
str nan str
nan str str
Run Code Online (Sandbox Code Playgroud)
我试过,df['ColA+ColB'] = df['ColA'] + df['ColB']但是如果任一列都是nan,则会创建一个nan值.我也考虑过使用concat.
我想我可以选择那个,然后使用一些,df.ColA+ColB[df[ColA] = nan] = df[ColA]但这似乎是解决方法.
我试图使用,Application.Match但它返回一个type mismatch error:13错误.为什么?
Dim mySrs as Series
Dim ws as Worksheet
set ws Activesheet
For Each mySrs in ActiveChart.SeriesCollection
tempvar = mySrs.Name
y = Application.Match(tempvar, ws.Range("P37:P71"), 0)
MsgBox y
Run Code Online (Sandbox Code Playgroud) 我创建了一个非常简单的堆积条形图,但由于某种原因,我的x-tick标签偏离中心.我尝试使用一些tick.label.set_属性来排列它们无济于事.有什么建议?谢谢!
码:
bottom = np.vstack((np.zeros((data.shape[1],), dtype=data.dtype), np.cumsum(data, axis=0) [:-1]))
for dat, col, bot, lab in zip(data, colors, bottom, labels):
ax1.bar(ind, dat, color=col, bottom = bot, alpha = .7, label = lab)
xticks([z for z in range(0,len(income_brackets))],[(str("{0:.0f}".format(k/1000)) + '-' + str("{0:.0f}".format(l/1000))) for k,l in income_brackets])
for tick in ax1.xaxis.get_major_ticks():
tick.label.set_fontsize(12)
tick.label.set_horizontalalignment('left')
Run Code Online (Sandbox Code Playgroud)
图片:

我有一份高中名单.我想从字符串中删除某些字符,单词和符号.
我目前有:
df['schoolname'] = df['schoolname'].str.replace('high', "")
Run Code Online (Sandbox Code Playgroud)
不过,我想用一个列表,以便我能快捷地更换high,school,/,等.
有什么建议?
df['schoolname'] = df['schoolname'].str.replace(['high', 'school'], "")
Run Code Online (Sandbox Code Playgroud)
不起作用
我有类似的数据:
id value duplicate
a 200 yes
a 12 yes
b 42 yes
c 12 no
b 532 yes
b 21 yes
...
Run Code Online (Sandbox Code Playgroud)
跟踪我使用的重复项df['duplicate'] = df.duplicated('id', keep=False)但是,我想保留最高的那些value并且标记或删除其他重复项.有什么建议?
我有两列如下:
id, colA, colB
0, a, 13
1, a, 52
2, b, 16
3, a, 34
4, b, 946
etc...
Run Code Online (Sandbox Code Playgroud)
我正在尝试创建第三列colC,即colBif colA == a,否则0。
这是我在想的,但是不起作用:
data[data['colA']=='a']['colC'] = data[data['colA']=='a']['colB']
Run Code Online (Sandbox Code Playgroud)
我也在考虑使用np.where(),但我认为这在这里行不通。
有什么想法吗?
我一直在看数学符号和不同的包,但还没有找到任何让我打印xbar(平均x)的东西.
我希望在matplotlib中使用xbar作为标签.
有什么建议?
谢谢.干杯
我正在尝试选择具有某个类的所有元素。他们可能在这门课之前或之后有不同的课程,但只要他们有这门课就应该被选中
前任:
<g class="class a, class b, class c">
<g class="class q, class r, class z">
<g class="class d, class b, class e">
Run Code Online (Sandbox Code Playgroud)
我希望选择第 1 个和第 3 个元素,因为它们都在class b. 有什么建议?我以为d3.selectAll(".class b")会工作,但它没有。
我有一个dataframe1带有列的DataFrame ['A', 'B', 'C', 'D'].
我有另一个DataFrame dataframe2如下:
Old_Names New_Names
A 1st
B 2nd
C 3rd
D 4th
Run Code Online (Sandbox Code Playgroud)
如何使用dataframe2更改列名dataframe1到['1st', '2nd', '3rd', '4th']?
所以我已经阅读了一些SO帖子和一些博客,但仍然无法弄清楚为什么我的代码不起作用.
我的代码:
function myFunct(d) {
if (typeof d.parent.name == "undefined") {
console.log("undefined") ;} else { console.log("defined") ;}
}
Run Code Online (Sandbox Code Playgroud)
d 是一个看起来像这样的对象:
Object {
children: Object,
count: 676
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试使用(!d.parent.name),hasOwnProperty,===,和如上面使用typeof.有什么建议?
我收到的错误是 TypeError: d.parent.name is undefined
更新:
好的,感谢大家的投入,如果问题令人困惑,我道歉.我实际上是在寻找,d.parent.parent但试图通过使用来简化问题d.parent.我认为问题是d.parent没有定义,所以它甚至没有达到d.parent.parent.抱歉没有更具体!
python ×6
pandas ×5
if-statement ×2
javascript ×2
matplotlib ×2
python-2.7 ×2
string ×2
text ×2
bar-chart ×1
d3.js ×1
duplicates ×1
excel ×1
excel-vba ×1
function ×1
labels ×1
notation ×1
replace ×1
select ×1
undefined ×1
vba ×1