首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将两个不同字典中的数据帧连接到python中的一个新数据框架中?

如何将两个不同字典中的数据帧连接到python中的一个新数据框架中?
EN

Stack Overflow用户
提问于 2019-11-06 08:46:08
回答 1查看 82关注 0票数 1

这是我的示例代码

代码语言:javascript
复制
dataset_current=dataset_seq['Motor_Current_Average']
dataset_consistency=dataset_seq['Consistency_Average']

#technique with non-overlapping the values(for current)
dataset_slide=dataset_current.tolist()
from window_slider import Slider
import numpy
list = numpy.array(dataset_slide)
bucket_size = 336
overlap_count = 0
slider = Slider(bucket_size,overlap_count)
slider.fit(list)      
empty_dictionary = {}
count = 0
while True:
  count += 1
  window_data = slider.slide()
  empty_dictionary['df_current%s'%count] = window_data
  empty_dictionary['df_current%s'%count] =pd.DataFrame(empty_dictionary['df_current%s'%count])
  empty_dictionary['df_current%s'%count]= empty_dictionary['df_current%s'%count].rename(columns={0: 'Motor_Current_Average'})
  if slider.reached_end_of_list(): break
  locals().update(empty_dictionary)


#technique with non-overlapping the values(for consistency)
dataset_slide_consistency=dataset_consistency.tolist()
list = numpy.array(dataset_slide_consistency)
slider_consistency = Slider(bucket_size,overlap_count)
slider_consistency.fit(list)      
empty_dictionary_consistency = {}
count_consistency = 0
while True:
  count_consistency += 1
  window_data_consistency = slider_consistency.slide()
  empty_dictionary_consistency['df_consistency%s'%count_consistency] = window_data_consistency
  empty_dictionary_consistency['df_consistency%s'%count_consistency] =pd.DataFrame(empty_dictionary_consistency['df_consistency%s'%count_consistency])
  empty_dictionary_consistency['df_consistency%s'%count_consistency]= empty_dictionary_consistency['df_consistency%s'%count_consistency].rename(columns={0: 'Consistency_Average'})
  if slider_consistency.reached_end_of_list(): break
  locals().update(empty_dictionary_consistency)
import pandas as pd
output_current ={}
increment = 0
while True:
   increment +=1
   output_current['dataframe%s'%increment] = pd.concat([empty_dictionary_consistency['df_consistency%s'%count_consistency],empty_dictionary['df_current%s'%count]],axis=1)

我的问题是,我有两个字典,每个字典中包含79个数据帧,即"empty_dictionary_consistency“和"empty_dictionary”。我想为其中的每一个创建一个新的数据框架,以便将empty_dictionary_consistency中的df1与来自empty_dictionary .So的df1连接起来,从从empty_dictionary_consistency到df1从empty_dictionary到df79从empty_dictionary_consistency到df79从empty_dictionary连接开始。我尝试使用while循环来增加它,但是没有显示任何输出。

代码语言:javascript
复制
output_current ={}
increment = 0
while True:
   increment +=1
   output_current['dataframe%s'%increment] = pd.concat([empty_dictionary_consistency['df_consistency%s'%count_consistency],empty_dictionary['df_current%s'%count]],axis=1) 

有人能帮我吗?我该怎么做呢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-11-06 10:39:00

我现在不在我的电脑附近,所以我不能测试代码,但问题似乎在索引中。在最后一个循环中,在每次迭代中都会增加一个名为“增量”的变量,但您仍然要将前面循环中的索引用于要连接的字典。尝试将用于索引所有字典的变量更改为“增量”。还有一件事-我看不出这个循环什么时候会结束?

我的意思是:

代码语言:javascript
复制
length = len(empty_dictionary_consistency)
increment = 0 
while increment < length: 
    increment +=1
    output_current['dataframe%s'%increment] = pd.concat([empty_dictionary_consistency['df_consistency%s'%increment],empty_dictionary['df_current%s'%increment]],axis=1) 

在遍历字典时,应该使用一个变量作为所有三个字典中的索引。一旦在循环中不使用Slider对象,就必须在第一个字典结束时停止它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58726161

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档