首页 \ 问答 \ R的等价物与Python中的条件相当(Equivalent of R's sapply with a condition In Python)

R的等价物与Python中的条件相当(Equivalent of R's sapply with a condition In Python)

我试图将R代码转换为Python,并需要在python中找到相当于sapply的东西。

data <- data[, sapply(data, class) != "logical"]

所以它做的是从数据集中删除逻辑列(如果有的话)。

对于以下数据:

Name    Designation         YrofExp     True DS
V       Data Scientist      15          TRUE
P       Data Scientist      10          TRUE
S       Senior Data Analyst 6           FALSE
H       Senior Data Analyst 8           FALSE

str(data)
'data.frame':   4 obs. of  4 variables:
 $ ï..Name    : Factor w/ 4 levels "H","P","S","V": 4 2 3 1
 $ Designation: Factor w/ 2 levels "Data Scientist",..: 1 1 2 2
 $ Yr.of.Exp  : int  15 10 6 8
 $ True.DS    : logi  TRUE TRUE FALSE FALSE
> data <- data[, sapply(data, class) != "logical"]
> str(data)
'data.frame':   4 obs. of  3 variables:
 $ ï..Name    : Factor w/ 4 levels "H","P","S","V": 4 2 3 1
 $ Designation: Factor w/ 2 levels "Data Scientist",..: 1 1 2 2
 $ Yr.of.Exp  : int  15 10 6 8

我知道map函数可以像map(函数,数据)一样使用,但在这种情况下并不完全确定。

所以有人可以帮帮我!


I am trying to convert an R code to Python and need to find an equivalent of sapply in python.

data <- data[, sapply(data, class) != "logical"]

So what it does is remove logical columns if any from the dataset.

For the below data:

Name    Designation         YrofExp     True DS
V       Data Scientist      15          TRUE
P       Data Scientist      10          TRUE
S       Senior Data Analyst 6           FALSE
H       Senior Data Analyst 8           FALSE

str(data)
'data.frame':   4 obs. of  4 variables:
 $ ï..Name    : Factor w/ 4 levels "H","P","S","V": 4 2 3 1
 $ Designation: Factor w/ 2 levels "Data Scientist",..: 1 1 2 2
 $ Yr.of.Exp  : int  15 10 6 8
 $ True.DS    : logi  TRUE TRUE FALSE FALSE
> data <- data[, sapply(data, class) != "logical"]
> str(data)
'data.frame':   4 obs. of  3 variables:
 $ ï..Name    : Factor w/ 4 levels "H","P","S","V": 4 2 3 1
 $ Designation: Factor w/ 2 levels "Data Scientist",..: 1 1 2 2
 $ Yr.of.Exp  : int  15 10 6 8

I know that the map function can be used like map(function,data) but not exactly sure how in this case.

So can someone please help me out!


原文:https://stackoverflow.com/questions/49693198
更新时间:2022-04-01 18:04

最满意答案

你可以试试这个,

    final OpenRequest openRequest = new Session.OpenRequest((Activity) context);

    List<String> permissions = new ArrayList<String>();
    permissions.add("email");
    openRequest.setPermissions(permissions);

然后在检查访问令牌加载后你可以写这个

session.openForRead(openRequest.setCallback(statusCallback));

上面提到的过程对我有用,因为我只需要用户的电子邮件。

希望这会有所帮助..


I solved deleting application from facebook, so I reseted the permission. https://www.facebook.com/settings?tab=applications

相关问答

更多
  • 这是可能的,但需要分两个阶段完成。 首先,您必须向用户显示您自己的对话框,以便他们可以选择自己喜欢的权限。 其次,您必须通过Facebook对话框授权用户使用所选权限。 如果你正在寻找一个例子,Facebook Graph Explorer已经这样做了: http : //developers.facebook.com/tools/explorer/ 更大的问题是跟踪用户的可用权限并做出反应。 This would be possible but it would need to be done in tw ...
  • 您将包含最新的PHP SDK,但您的代码是为旧SDK编写的。 因此,要么降级到以前版本的SDK,要么更改您的实现。 // Old SDK $facebook->api_client->users_setStatus($_POST['hello']); // New SDK $facebook->api ( array( 'method' => 'users.setStatus' , 'status' => $_POST['hello'] , 'uid' => /* user's ...
  • 请参阅HelloFacebook示例应用程序,了解如何正确请求发布权限并发布。 您的代码的问题在于您正在请求发布权限(这是一个异步请求),并且在发出请求后立即发出请求,但是在发布请求时,您还没有收到发布权限的响应请求,这就是帖子失败的原因。 另外,另外,为什么在发布发布权限请求时禁止SSO? Please refer to the HelloFacebook sample app on how to properly request publish permissions and post. The pro ...
  • 在Facebook应用程序启动后,是否可以更改Facebook应用程序所需的权限? 如果是这样,已批准该应用的用户会怎样? 是的 什么发生了什么意思? 显然,您的应用只会使用用户授予的权限。 而已。 因此,您应该再次询问用户新的权限。 Facebook应用程序“异步”通知用户有关某事的建议方法是什么? 这完全取决于您想要什么以及如何实施。 有没有办法只需要默认的基本权限? 不要求任何额外的权限,就是这样! Facebook应用程序可以从第3方的页面读取/发布到第3方的页面,而用户不是该页面的管理员吗? 如果 ...
  • 实际上,最好订阅auth.authResponseChange事件。 这在Event.subscribe文档中列为最佳实践。 在大多数情况下,您需要订阅auth.authResponseChange而不是auth.statusChange 。 响应作为javascript数组返回,未编码为JSON。 更新: 似乎这对你来说也不适用,因为如果你打电话给Facebook的API,可能会不时调用它,可能还有其他情况,比如登录/注销。 Facebook JS-SDK中并不存在您所要求的内容,并且间隔似乎是一种选择。 ...
  • 你可以试试这个, final OpenRequest openRequest = new Session.OpenRequest((Activity) context); List permissions = new ArrayList(); permissions.add("email"); openRequest.setPermissions(permissions); 然后在检查访问令牌加载后你可以写这个 session.openFo ...
  • 而不是这个: # req_perms is a comma separated list of the permissions needed $url = $facebook->getLoginUrl(array('req_perms' => 'email,user_birthday,status_update,publish_stream,user_photos,user_videos')); 尝试: $url = $facebook->getLoginUrl(array('scope' => 'ema ...
  • 更新 : 好吧,我自己无法真正测试它,所以只需要一些建议就可以尝试。 将$loginUrl更改为: $loginUrl = $facebook->getLoginUrl(array( 'req_perms' => 'publish_stream', 'next' => 'http://'.$_SERVER['SERVER_NAME'].'/success.php', 'cancel_url' => 'http://'.$_SERVER['SERVER_NAME'].'/cancel. ...
  • 您需要覆盖Fragment类中的onActivityResult方法并将其传递给会话以完成会话转换。 无论您是否使用UiLifecycleHelper,都需要这样做。 You need to override the onActivityResult method in your Fragment class and pass it on to the session in order to complete the session transitions. This needs to happen reg ...
  • 这个答案可能会迟到。 我有一个类似的问题,使用适用于Android的FB SDK 3.0。 这是SDK中的一个错误,他们已经在3月20日发布的适用于Android的FB SDK 3.0.1中修复了它。 更改日志提到: “Web视图登录”对话框包含正在请求新权限的方案的令牌信息。 这避免了每当请求会话的新权限时用户必须输入其登录凭证。 升级后再试一次。 从这里获取新的SDK。 Might be a late for this answer. I had a similar problem, with the ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。