python - Creating user defined function for joins (Python)
问题描述
I am looking for an easy way to define a function that will consecutively join tables when ran. I am pretty new to Python, but have been given the task of building out a package that heavily relies on joins to work successfully.
I have done plenty of work in R, but will be finishing this in Python (unless I just hit a wall). The goal is to automate a complete task to where a dataframe could be inserted, pushed through a function, and then a presented in a couple different views. This would require one function for each view. Because of this, there are a
This is horrible, and as I am familiar with dplyr, I'm trying to use dfply to accomplish this.
def get_hcc(df, df2, df3):
df = (df >> inner_join(df2, by=[('col1', 'col2'), ('col1', 'col3')]))
df = df.drop_duplicates()
df = (df3 >> left_join(df, by = 'col4'))
return df
If anyone has better ideas as to how to go about this, that would be greatly appreciated!
Thanks.
解决方案
推荐阅读
- linux - 使用 linux 选项发布的 winforms 应用程序是否在 linux 操作系统上运行?
- javascript - 是否有可能在伊斯坦布尔 JS 覆盖率报告中查看哪些测试实际上负责覆盖这条线?
- python - 使用 Python 将此 Json 文件添加到 mySQL 数据库中
- kdb - 如何在kdb中排除字符串中的一些记录?
- python - 用于检查回文词的递归函数背后的逻辑
- python - 如何调整和清理当前格式为混乱的时间字符串的时间列表?
- c# - 如何访问派生自 PageModel 的类中的 HTTPContext?
- python - 如何使用并发期货更快地进行网络抓取?硒
- python - 让 Pandas 在 DataFrame 的索引上绘制实际值,而不是它出现的频率
- java - 如何使用新功能创建我自己的 Set Class