大熊猫系列的垂直合并

时间:2017-08-01 17:30:48

标签: python-3.x pandas dataframe merge series

我目前有两个共享一个公共列的数据帧,如下所示:

df1 = 
    Text    Val
    "This"     1
    "That"     2
    "Is"       3
    "Not"      ''
    "Working"  ''

df2 = 
    Text    Val
    "This"     ''
    "That"     ''
    "Is"       ''
    "Not"      4
    "Working"  5

我想以下列方式合并两个数据帧:

merged_df = 
    Text    Val
    "This"     1
    "That"     2
    "Is"       3
    "Not"      4
    "Working"  5

基本上,两个数据帧df1和df2都共享一个共同的" Text"柱。所有值都相似。但是,在df1中,对应于" Not"的行没有值。和"工作",但这些在df2中可用。

如何将这些堆叠在一起以提出merged_df?

与我的实际数据相比,这些示例微不足道,但希望这有助于

1 个答案:

答案 0 :(得分:3)

您可以使用combine_firstset_index对齐数据并替换为import { Component, OnInit } from '@angular/core'; import { IProduct } from './product'; import { ProductService } from './product.service'; @Component({ templateUrl: './product-list.component.html' }) export class ProductListComponent implements OnInit { _listFilter: string; get listFilter(): string { return this._listFilter; } set listFilter(value: string) { this._listFilter = value; this.filteredProducts = this.listFilter ? this.performFilter(this.listFilter) : this.products; } filteredProducts: IProduct[]; products: IProduct[] = []; constructor(private _productService: ProductService) { } performFilter(filterBy: string): IProduct[] { filterBy = filterBy.toLocaleLowerCase(); return this.products.filter((product: IProduct) => product.productName.toLocaleLowerCase().indexOf(filterBy) !== -1); } ngOnInit(): void { this._productService.getProducts() .subscribe(products => { this.products = products; this.filteredProducts = this.products; }, error => this.errorMessage = <any>error); } } s(如有必要):

NaN