import pandas as pd
import numpy as np
df = pd.DataFrame({
'A1': [1,0,0,0,1,1,0,0,1,0,0,0,1,1,1,0]})
A2 = []
#loop through every fourth value
for i in range(int(len(df)/4)):
#get the current four values
current_four = df.iloc[i*4: (i*4) + 4]
#convert the values to strings to join them together
new_entry = ''.join(map(str, list(current_four['A1'])))
A2.append(int(new_entry))
result_df = pd.DataFrame({'A2': A2})
1条答案
按热度按时间nr7wwzry1#
注:由于第二列只有4行,而第一列有16行,因此将存在维不匹配。因此,您必须将第二列保存在第二个 Dataframe 中,或者为每个A1值重复A2标签
除此之外,这应该工作,以获得您正在寻找的A2值。