我有一个pandas数据帧,我想根据数据框中两列的值过滤整个df.我想找回IBRD或IMF!= 0的所有行和列.
alldata_balance = alldata[(alldata[IBRD] !=0) or (alldata[IMF] !=0)]
Run Code Online (Sandbox Code Playgroud)
但这给了我一个ValueError
ValueError:Series的真值是不明确的.使用a.empty,a.bool(),a.item(),a.any()或a.all().
所以我知道我没有正确使用或声明,有没有办法做到这一点?
我希望利用Plotly中的强大功能,但我很难弄清楚如何将回归平面添加到三维散点图中.以下是如何开始使用3d绘图的示例,是否有人知道如何在下一步中添加并添加平面?
library(plotly)
data(iris)
iris_plot <- plot_ly(my_df,
x = Sepal.Length,
y = Sepal.Width,
z = Petal.Length,
type = "scatter3d",
mode = "markers")
petal_lm <- lm(Petal.Length ~ 0 + Sepal.Length + Sepal.Width,
data = iris)
Run Code Online (Sandbox Code Playgroud) 我昨天搞砸了并将数据框保存到了csv,在那个数据框中我有一个列是一个字符串列表.现在,当我从csv将其导入python时,字符串列表是一个字符串(字符串列表).有没有办法在导入时将其更改回字符串列表?
例:
testList = localGov["DataElements"][4]
testList
Out[62]: "['Ethnicity', 'Sex', 'Cause of Death', 'Count', 'Percent']"
Run Code Online (Sandbox Code Playgroud)
我能够得到的最接近的是使用以下内容,但它在一些角色前面留下了一个空格.
testList.strip("[]").replace("'","").split(",")
Out[74]: ['Ethnicity', ' Sex', ' Cause of Death', ' Count', ' Percent']
Run Code Online (Sandbox Code Playgroud) 我在 R 中有一个 data.frame,它是每支球队在多个赛季中的棒球比赛结果目录。一些列是team
, opponent_team
, date
, result
, team_runs
, opponent_runs
, 等。那一行。
例如
team opponent_team date result team_runs opponent_runs
BAL BOS 2010-04-05 W 5 4
Run Code Online (Sandbox Code Playgroud)
在其他地方有另一行
team opponent_team date result team_runs opponent_runs
BOS BAL 2010-04-05 L 4 5
Run Code Online (Sandbox Code Playgroud)
我想编写一些代码dplyr
或类似的代码来选择具有,和列的独特组合的行。我在这里强调单词组合,因为顺序无关紧要,我只是想摆脱镜像的行。team
opponent_team
date
谢谢