简体   繁体   English

使用 Pandas DataFrame,如何保留每 7 行?

[英]With a pandas DataFrame, how do I keep every 7th row?

如果我的DataFrame有 100 行,我想保留第 7 行,从第一行开始。

假设df是您的数据框,请尝试:

df[::7]

HERE :

import pandas as pd
import numpy as np
df = pd.DataFrame({'A' : np.random.randint(1, 100, 100)})
df.iloc[np.arange(0, 100, 7)]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何每第 4 行将 append 列总计到 pandas dataframe? - How to append column total to pandas dataframe every 4th row? 我怎样才能总结熊猫数据帧中每 x 列和 x+2 列的列? - How can I sum up colum every x-th and x+2-th column in pandas dataframe? 如何使用Python遍历第4行中的第4个像素? - How do I loop through every 4th pixel in every 4th row, using Python? 如何从三个熊猫列中获得第 3 到第 7 个最高选择的平均值? - How can I get the average of the 3rd to 7th highest selection from three pandas columns? 如何在 pandas dataframe 中每隔 4 行 select 并计算滚动平均值 - How to select every 4th row in a pandas dataframe and calculate the rolling average 如何向 pandas dataframe 添加一列,该列在一个范围内具有最高值但将其应用于每一行? - How do I add a column to a pandas dataframe which has the highest value in a range but applying it to every row? 如何在pandas数据帧中为每行文本填充所有带空格的标点符号? - How do I pad all punctuation with a whitespace for every row of text in a pandas dataframe? 如何在熊猫数据框中从当前行中减去前一行并将其应用于每一行; 不使用循环? - How do I subtract the previous row from the current row in a pandas dataframe and apply it to every row; without using a loop? 对熊猫数据框的每一行做一些事情 - Do something to every row on a pandas dataframe 熊猫-如何按行索引访问数据帧中的行 - pandas - How do I access row in a dataframe by row Index
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM