本文整理汇总了Python中pandas.merge_ordered方法的典型用法代码示例。如果您正苦于以下问题:Python pandas.merge_ordered方法的具体用法?Python pandas.merge_ordered怎么用?Python pandas.merge_ordered使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandas
的用法示例。
在下文中一共展示了pandas.merge_ordered方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_multigroup
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import merge_ordered [as 别名]
def test_multigroup(self):
left = pd.concat([self.left, self.left], ignore_index=True)
left['group'] = ['a'] * 3 + ['b'] * 3
result = merge_ordered(left, self.right, on='key', left_by='group',
fill_method='ffill')
expected = DataFrame({'key': ['a', 'b', 'c', 'd', 'e', 'f'] * 2,
'lvalue': [1., 1, 2, 2, 3, 3.] * 2,
'rvalue': [nan, 1, 2, 3, 3, 4] * 2})
expected['group'] = ['a'] * 6 + ['b'] * 6
assert_frame_equal(result, expected.loc[:, result.columns])
result2 = merge_ordered(self.right, left, on='key', right_by='group',
fill_method='ffill')
assert_frame_equal(result, result2.loc[:, result.columns])
result = merge_ordered(left, self.right, on='key', left_by='group')
assert result['group'].notna().all()
示例2: test_doc_example
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import merge_ordered [as 别名]
def test_doc_example(self):
left = DataFrame({'group': list('aaabbb'),
'key': ['a', 'c', 'e', 'a', 'c', 'e'],
'lvalue': [1, 2, 3] * 2,
})
right = DataFrame({'key': ['b', 'c', 'd'],
'rvalue': [1, 2, 3]})
result = merge_ordered(left, right, fill_method='ffill',
left_by='group')
expected = DataFrame({'group': list('aaaaabbbbb'),
'key': ['a', 'b', 'c', 'd', 'e'] * 2,
'lvalue': [1, 1, 2, 2, 3] * 2,
'rvalue': [nan, 1, 2, 3, 3] * 2})
assert_frame_equal(result, expected)
示例3: process_amr_results
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import merge_ordered [as 别名]
def process_amr_results(self, amr_results_path, total_reads):
""" Writes processed amr result table with total_genes_hit, total_coverage,
and total_depth column values filled in for all genes to output files; and likewise with
the gene-family level summary of amr results table. """
amr_results = PipelineStepRunSRST2._get_pre_proc_amr_results(amr_results_path)
amr_summary = PipelineStepRunSRST2._summarize_amr_gene_families(amr_results)
amr_summary.to_csv(
self.output_files_local()[4],
mode='w',
index=False,
encoding='utf-8')
sorted_amr = amr_results.sort_values(by=['gene_family'])
proc_amr = pd.merge_ordered(sorted_amr, amr_summary, fill_method='ffill', left_by=['gene_family'])
proc_amr_with_rpm = PipelineStepRunSRST2._append_rpm_to_results(proc_amr, os.path.join(self.output_dir_local, MATCHED_READS_FILE), total_reads)
proc_amr_with_rpm_and_dpm = PipelineStepRunSRST2._append_dpm_to_results(proc_amr_with_rpm, total_reads)
proc_amr_with_rpm_and_dpm.to_csv(
self.output_files_local()[3],
mode='w',
index=False,
encoding='utf-8')
示例4: test_basic
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import merge_ordered [as 别名]
def test_basic(self):
result = merge_ordered(self.left, self.right, on='key')
expected = DataFrame({'key': ['a', 'b', 'c', 'd', 'e', 'f'],
'lvalue': [1, nan, 2, nan, 3, nan],
'rvalue': [nan, 1, 2, 3, nan, 4]})
assert_frame_equal(result, expected)
示例5: test_ffill
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import merge_ordered [as 别名]
def test_ffill(self):
result = merge_ordered(
self.left, self.right, on='key', fill_method='ffill')
expected = DataFrame({'key': ['a', 'b', 'c', 'd', 'e', 'f'],
'lvalue': [1., 1, 2, 2, 3, 3.],
'rvalue': [nan, 1, 2, 3, 3, 4]})
assert_frame_equal(result, expected)
示例6: merge_ordered
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import merge_ordered [as 别名]
def merge_ordered(
left,
right,
on=None,
left_on=None,
right_on=None,
left_by=None,
right_by=None,
fill_method=None,
suffixes=("_x", "_y"),
how: str = "outer",
) -> DataFrame:
if not isinstance(left, DataFrame):
raise ValueError(
"can not merge DataFrame with instance of type {}".format(type(right))
)
ErrorMessage.default_to_pandas("`merge_ordered`")
if isinstance(right, DataFrame):
right = to_pandas(right)
return DataFrame(
pandas.merge_ordered(
to_pandas(left),
right,
on=on,
left_on=left_on,
right_on=right_on,
left_by=left_by,
right_by=right_by,
fill_method=fill_method,
suffixes=suffixes,
how=how,
)
)