有什么方法可以将python pandas数据帧发布为松弛状态? [英] What are some ways to post python pandas dataframes to slack?

查看:114
本文介绍了有什么方法可以将python pandas数据帧发布为松弛状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将熊猫数据框导出到松弛状态?

How can I export a pandas dataframe to slack?

df.to_json()看起来像是一个潜在的候选对象,再加上传入的Webhook松弛,但是对消息进行解析以将其显示为一个不错的markdown/html化表格对我来说并不明显.

df.to_json() seems like a potential candidate, coupled with the slack incoming webhook, but then parsing the message to display as a nice markdown/html-ized table isn't obvious to me.

长时间的聆听者,第一次的来电者,请对我轻松一点...

Long time listener, first time caller, please go easy on me...

推荐答案

Slack似乎不接受任意HTML输入或使用转义符换行符限制纯文本格式的文本.如另一个答案中所建议的,tabulate可以工作,但是如果您希望自己包含的东西可以工作.假设您的数据框在df

Slack doesn't seem to take arbitrary HTML input or format text with escaped newlines which limits to plain text. tabulate as suggested in another answer works, but if you want something that is self contained this would work. Assuming your data frame is in df

  1. 在python终端会话中,jupyter笔记本或print语句运行类似print(repr(df))的内容.
  2. 复制输出
  3. 以松弛方式粘贴代码块.
  1. In python terminal session, jupyter notebook, or print statement run something like print(repr(df)).
  2. Copy the output
  3. Paste in code blocks in slack.

对于我手头的数据框,这是您在按Enter键之前在闲聊框中输入的内容.

For the data frame I had on hand this is what you would enter in the slack chat box before hitting enter.

```
   code    sid state        triplet
0  SCAN   2057    AL   2057:AL:SCAN
1  SNOW    ABY    CA    ABY:CA:SNOW
2  SNOW  15A21    MT  15A21:MT:SNOW
3  COOP   0010    ID   0010:ID:COOP
4  SNOW  1F01A    BC  1F01A:BC:SNOW
```

如果要将其集成为Web服务,则将复制/粘贴内容替换为Web服务/挂钩.

If you wanted to integrate this as a web service replace the copy/paste stuff with web services/hooks.

这篇关于有什么方法可以将python pandas数据帧发布为松弛状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆