- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在使用 Python 进行分析,通过计算交互次数和阅读消息来了解我们在社交媒体 channel 中保持对话多长时间。
我认为方法是让第一个表看起来像第二个表。到达那里的步骤:
现在时间戳对我来说不是那么重要,但它可能在未来。无论如何,我会使用与入站和出站消息相同的技术
餐 table 前
Inbound Message Outbound message Inbound Time Outbound Time Account Hello, how are you @userA I'm good! mm/dd/yy hh:mm mm/dd/yy hh:mm FB Where is the cat? @userB what cat? mm/dd/yy hh:mm mm/dd/yy hh:mm Twitter What is a pie @user3 it is a food mm/dd/yy hh:mm mm/dd/yy hh:mm Twitter The black cat @userB I don't know mm/dd/yy hh:mm mm/dd/yy hh:mm Twitter
餐 table 后
User Messages Account Inbound 1 Outbound 1 Inbound 2 Outbound 2 Inbound 3 Outbound 3 userA 1 FB Hello, how are you @user1 I'm good! null null null null userB 2 Twitter Where is the cat? @user2 what cat? The black cat @user2 I don't know null nulluser3 1 Twitter What is a pie @user3 it is a food null null null null
最佳答案
注意
您需要 groupby
user
和 df.Account
因为同一用户可能有来自不同帐户的消息。
# helper function to flatten multiindex objects
def flatten_multiindex(midx, sep=' '):
n = midx.nlevels
tups = zip(*[midx.get_level_values(i).astype(str) for i in range(n)])
return pd.Index([sep.join(tup) for tup in tups])
in_out = ['Inbound Message', 'Outbound message']
# this gets a fresh ordering for each group
handler = lambda df: df.reset_index(drop=True)
# Use regular expression to extract user
user = df['Outbound message'].str.extract(r'(?P<User>@\w+)', expand=False)
df1 = df.groupby([user, df.Account])[in_out].apply(handler) \
.unstack().sort_index(1, 1)
df1.columns = flatten_multiindex(df1.columns)
# I separated getting group sizes from long to wide pivot
messages = df.groupby([user, df.Account]).size().to_frame('Messages')
pd.concat([messages, df1], axis=1)
pd.concat([messages, df1], axis=1).reset_index()
分解辅助函数
# helper function to flatten multiindex objects
def flatten_multiindex(midx, sep=' '):
# get the number of levels in the index
n = midx.nlevels
# for each level in the index, get the values and
# convert it to strings so I can later ' '.join on it
#
# zip forms the tuples so I can pass each result to ' '.join
tups = zip(*[midx.get_level_values(i).astype(str) for i in range(n)])
# do the ' '.join and return as an index object
return pd.Index([sep.join(tup) for tup in tups])
关于python - 将文本解析到它自己的字段中,计数并将选择字段 reshape 为宽格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39310464/
函数参数中或显示尺寸时(高度,宽度)的顺序是否有约定? 最佳答案 我不知道大量的语言,但我使用过的语言(宽度,高度)。它更适合沿着 (x, y) 坐标线。 关于language-agnostic -
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 6 年前。 Improve th
有没有办法显示自定义宽度/高度的YouTube视频? 最佳答案 在YouTube网站上的this link中: You can resize the player by editing the obj
如何从此表单获取数据(数据的长表示): import pandas as pd df = pd.DataFrame({ 'c0': ['A','A','B'], 'c1': ['b',
我在让宽度为 900px 的页面在宽度低于 900px 的分辨率下看起来不错时遇到了一些麻烦。这包括智能手机等移动设备。看起来我在页面上放大了,但无法滚动或缩小。我的页面包装器被定义为以屏幕为中心。这
我有一个包含一个表的 div,它有另一个带有动态变化文本的 div。div 有样式 overflow: hidden; white-space: nowrap; text-overflow: elli
我一直在愚弄下面的html代码。我已将 div id ="mainWide"设置为 2500 像素的宽度,这比我的屏幕还宽,我希望在主浏览器窗口中有一个水平滚动条,而不是在 div block 本身中
当我的屏幕浏览器窗口在 992px-1199px 之间时,我的文章元素比它们的父 div (.wrapper) 更宽。所以在这个屏幕宽度下,面板重叠并且看起来不对。 在所有其他屏幕宽度下,我的代码都准
我在对齐某些行时遇到了一些问题。我正在显示一个占据视口(viewport) 100% 高度的部分。因此,当您在屏幕上查看此部分时,您只会看到此部分。 在这个部分中,我有一个标题和副标题。标题应显示在节
为什么表单输入字段比其父 div 宽?宽度应用于文本 div,但不应用于其中包含表单字段的 div。为什么会这样? See the livecode here. .parent { width:
我想让这个标题 100% 宽。我在 jsfiddle 上试过这个,但是左边和右边还有一些余量。 CSS: #header { background: url("../img/top-bg.png
我的页面宽度有问题。无论我尝试什么,它的左边或右边都有白边(默认情况下在右边,如果我使用 margin-right:0 则在左边)。如果我使用 margin:0 比它留在右边。尝试了我所知道的一切,但
我有一个带有背景图片的宽 div。 div 的宽度为 1100 像素,当浏览器窗口小于该宽度时,会出现滚动条。有什么办法可以避免滚动条吗?那不是任何黑客。现在我知道我可以把它放在 body image
我有一个您可以访问的应用程序 here .当您打开应用程序时,只需单击加号按钮,您就会看到一个带有搜索栏的模态窗口。 现在请执行这两个搜索: 搜索 1:AAA 搜索 2:AAE 您会看到,在 AAE
这个问题在这里已经有了答案: Does element width include padding? (5 个答案) 关闭 7 年前。 HTML CSS .wrap{widt
我正在尝试在工具栏中创建一个自定义显示,类似于 Xcode 工具栏中心的信息 Pane 。 我们如何创建一个宽度超过 32 点的 NSToolbarItem? 框架始终将其限制为 32 点,即使最小和
我想将df1转换成df2 旧示例数据框 df1 df1 长),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/359
我正在使用 JavaScript 代码在 FireBase/FireStore 中上传图像。 核心功能已经可以运行,我可以上传,但我还需要在上传之前检查图像的大小。这就是我很乐意获得帮助的地方。 以下
如何在 Tkinter 中设置/更改 ttk.Separator 对象的长度/宽度? ttk.Separator(self, orient='horizontal').grid(c
我有一个简单的问题。为什么 a 不会自动调整其内容的大小?像这样: Test 返回 width:100%,尽管我希望“Test”这个词简单地居中。有什么想法吗? 最佳答案 您的问题与 HT
我是一名优秀的程序员,十分优秀!