# Stores new data in array for dataframe
highValues = []
for i in range(0, len(df), 2):
# Checks to see which "high" is higher
if (df.loc[i].at["high"] > df.loc[i+1].at["high"]):
# Appends data to array
newDataFrame.append(df.loc[i].at["high"])
if (df.loc[i].at["high"] < df.loc[i+1].at["high"]):
# Appends data to array
newDataFrame.append(df.loc[i+1].at["high"])
# Creates new pandas dataframe with array contents
newDF = pd.DataFrame(highValues)
2条答案
按热度按时间pes8fvy91#
您可以执行以下操作:
k7fdbhmy2#
可以使用groupby将DF分组为2行一组,然后选择
'high'
最大的行。索引的整数除法排列2行一组: