如何在python中将来自两个不同字典的数据帧连接成一个新的数据帧?

逻辑

这是我的示例代码

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 ”。我想为它们中的每个创建一个新的数据帧,以便它将df1从empty_dictionary_consistency与df1从empty_dictionary进行连接。因此,它将从df1从empty_dictionary_consistency到df1从empty_dictionary到df79从empty_dictionary_consistency到df79从empty_dictionary_consistency到我尝试使用while循环将其递增,但未显示任何输出。

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) 

有人可以帮我吗?我怎样才能做到这一点。

弗拉德·里亚伯(Vlad Riabets)

我现在不在电脑旁,因此无法测试代码,但看来问题出在索引上。在最后一个循环中,在每次迭代中都递增一个名为“ increment”的变量,但仍将先前循环中的索引用于要连接的字典。尝试将用于索引所有字典的变量更改为“增量”。还有一件事-我看不到这个循环何时结束?

UPD我的意思是:

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对象,就必须在第一个字典结束时将其停止。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

将数据帧从循环连接成一个大数据帧

如何在Django中将两个功能不同的数据帧写入一个Excel文件

如何在SQL中将两列连接成一个新列?

使用 Pandas 比较两个数据帧以返回一个新的数据帧 - Python

将两个不同 columnName 的数据表连接成一个数据表

用一致的填充将数据帧行值连接成一个

如何连接来自两个不同数据帧的*具有给定条件*的行组合?

如何在 Python 中将不同的数据帧组合成一个 csv?

将来自两个不同数据帧的 2 列相乘,通过公因子匹配行

如何在R中组合来自不同数据帧的两个变量?

如何从两个数据帧中删除不匹配的数据,以在R中创建一个新的数据帧

Python:如何组合来自两个不同数据帧的特定列

从两个数据帧计算一个新的熊猫数据帧

如何在两个数据帧中查找值,以及如何在一个数据帧中的匹配行上添加新值

将来自不同文件的多个Excel工作表导入python,并将它们连接到一个数据帧中

如何合并两个不同长度的数据帧,一个是另一个的子集

如何将来自ggeffects R的数据帧列表合并到一个数据帧中?

连接两个不同长度的数据帧

将来自两个JavaScript对象的数据合并到一个新对象中

来自一个图(R)中两个数据帧的数据

在C中将两个整数连接成一个char *

连接两个包含数据帧的字典中的数据帧

如何在python中将更多稀疏矩阵连接成一个

减去两个大小不同的数据帧,但至少保持第一个数据帧的大小

将两个不同列表的数据帧融为r中的一个数据帧列表

连接两个数据帧,其中一个数据帧是其他数据集的子集

来自一个数据帧的 python subplot plot.bar 和来自不同数据帧的图例

如何在熊猫中将一个* m数据帧与一个1 * m数据帧相乘?

如何在R中使用ggplot2绘制来自不同数据帧的两个序列彼此相对,而不建立新的数据帧?