0
我想操纵一个熊猫df,这样我就可以计算出一列中某个数据点出现的频率,在另一列发生特定事件之后。下面的伪代码可能总结得最好。任何帮助将非常感激!熊猫列操纵
import datetime
import time
import pandas as pd
# Set number of rows to skip
rows_to_skip = 0
# Rows to use after skipped rows
rows_to_use = 10000
# Read the file (Adjust arguments accordingly)
data = pd.read_csv('example.csv',skiprows=rows_to_skip, error_bad_lines=False, nrows=rows_to_use, low_memory=False)
# Add headers when skipping rows
data.columns = ["X","Y","Z"]
# Psuedo Code Below
for variable in data['X']:
if variable > 0:
# Count number of times the following conditions are met in all subsequent rows:
condition 1) Y > 0
condition 2) Z <= Z of the row where variable was > 0
# Then I want to add the total count to a new column, and have it in the same row as X when the "variable" > 0.
任何帮助?
斯特凡,谢谢。很有帮助。但是我试图计算在X> 0的实例之后但在X> 0的下一行之前两个条件同时满足的次数(data.Y> 0和data.Z <= row.Z)。再次感谢! –
这就是我认为的第一个例子。 – Stefan
我已经更新,只留下解决您的问题的第一个例子。请让我知道,如果你有任何问题。 – Stefan