本文整理匯總了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,
)
)