在Python中创建多个非数字列的相关性
我有一个很长的数据框架,我想知道每个元素的相关性,实际数据帧大约为40列宽,所以我在此处编写了此示例。
标识符 | 列 | 1列2 | 列3 | 列4 |
---|---|---|---|---|
1 | 狗 | 羊羊 | 恐龙 | 我 |
2 | 狗 | 猪 | ||
3 | 牛 | 象 | 野猪, |
想要的是3个新列,看起来像该
标识符 | var1 | var2 1 var2 |
---|---|---|
1 | 狗 | 牛 |
1 | 狗 | 牛 |
1 | 狗 | 羊毛1狗恐龙 |
1 | 牛 | 绵羊 |
1 | 牛恐龙1羊 | 恐龙 |
1 | 羊 | 恐龙 |
2 | 狗 | 猪 |
3 | 牛 | 大象 |
3 | 公野 | 公猪 |
3 | 大 | 野猪 |
最终我需要它们这样的原因是在Tableau中创建一个相关矩阵(
如果您还知道其他任何创建相关矩阵的方法)在Tableau中创建一个相关矩阵在所有这些变量中,请让我知道,这是我发现的最佳方法,但无论如何我仍然需要创建这个新表。
还有一个额外的东西,使它更加困难和有趣!有时,某些列会为空,如果发生这种情况,则应该停止而不继续。
提前致谢
I have a very long data frame, I want to know the correlations of each and every element, the actual data frame is about 40 columns wide, so I am writing this example here.
Identifier | Column1 | Column2 | Column3 | Column4 |
---|---|---|---|---|
1 | Dog | Cow | Sheep | Dinosaur |
2 | Dog | Pig | ||
3 | Bull | Elephant | Boar |
What I want is 3 new columns that would look like this
Identifier | Var1 | Var2 |
---|---|---|
1 | Dog | Cow |
1 | Dog | Sheep |
1 | Dog | Dinosaur |
1 | Cow | Sheep |
1 | Cow | Dinosaur |
1 | Sheep | Dinosaur |
2 | Dog | Pig |
3 | Bull | Elephant |
3 | Bull | Boar |
3 | Elephant | Boar |
Eventually the reason I need them like this is to create a correlation matrix in tableau (It cannot be done in any other software)
If you guys know any other way to create a correlation matrix of all these variables, please let me know, this is the best way I found out but I still need to create this new table anyway.
And an extra to make it more difficult and interesting! Sometimes some of the columns will be empty, if that happens then it should stop and not continue.
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
输出:
output: