连接具有相似类型信息的两个数据帧

时间:2017-07-26 19:29:59

标签: python pandas

我有两个不同的数据框:

public void ConfigureServices(IServiceCollection services)
{

    services.AddSingleton<IDataProtectionProvider>(s => DataProtectionProvider.Create("WebApplication2"));

    services.Configure<CookieTempDataProviderOptions>(options =>
    {
        options.Path = "/";
    });
    services.AddSingleton<ITempDataProvider, CookieTempDataProvider>();
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ITempDataProvider tempDataProvider)
{
    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
    }

    app.Map("/page1", (app1) =>
    {
        app1.Run(async context =>
        {
            tempDataProvider.SaveTempData(context, new Dictionary<string, object> { ["Message"] = "Hello from page1 middleware" });
            await context.Response.WriteAsync("Hello World! I'm page1");
        });
    });

    app.Map("/page2", (app1) =>
    {
        app1.Run(async context =>
        {
            var loadTempData = tempDataProvider.LoadTempData(context);
            await context.Response.WriteAsync("Hello World! I'm page2: Message from page1: " + loadTempData["Message"]);
        });
    });
}

其中:

  1. 我不知道列的名称
  2. 两个数据帧都有类似的信息类型(即df1的第一列与df2的第2列相似)
  3. 但在其他情况下,数据帧没有相似类型的信息(即df2的第4列是唯一的)
  4. 话虽如此,是否可以构建以下数据框?

    df1 = pd.DataFrame(np.array([
        [53034667202, 'a', "1985-04-13 00:00:00"],
        [53044667062, 'b',  "1957-03-10 00:00:00"],
        [53034664082, 'c',  "1967-04-14 00:00:00"]]),
        )
    
    
    df2 = pd.DataFrame(np.array([
        ['D', 53034668762, "2017-04-13 00:00:00","blue 02"],
        ['E', 53034669142, "2017-04-13 00:00:00","red 004"],
        ['F', 53034664012, "2017-04-13 00:00:00", "green 450"]]),
       )
    

0 个答案:

没有答案