我首先从输入的csv文件创建一个数据框,然后得到正确的格式,但现在我需要对V,I和P列进行计算。我想使用时间戳分割数据。
即获得测试循环0和测试循环1之间所有值的V,I和P的均值。我知道我可以使用iloc执行此操作,但我正在尝试编写一个适用于不同日志文件的脚本可能有不同数量的条目。
如果您需要更多信息,请告知我们,我们非常感谢您的帮助/意见。
答案 0 :(得分:4)
我认为需要从列19
中提取第一个Time
值并汇总mean
:
df = df.groupby(df['Time'].str[:19]).mean()
如果需要删除NaN
s之前的行:
df = df.dropna()
df = df.groupby(df['Time'].str[:19]).mean()
答案 1 :(得分:2)
如果你想得到'测试循环'行之间的行的平均值:
首先,您需要提取时间窗口的限制:
means = []
for i in range(len(serie_time_limits)):
if i==len(serie_time_limits)-1:
df_window = df_data[(df_data['Time']>=serie_time_limits[i])
else:
df_window = df_data[(df_data['Time']>=serie_time_limits[i]) & (df_data['Time']<serie_time_limits[i+1])]
means.append(df_window[['V', 'I', 'P']].mean())
然后,您可以获得每个测试循环的平均值:
public Form1()
{
dataGridView1.Dock = DockStyle.Fill;
dataGridView1.AutoSizeColumnsMode =
DataGridViewAutoSizeColumnsMode.AllCells;
reportButton.Text = "Generate Report";
reportButton.Dock = DockStyle.Top;
reportButton.Click += new EventHandler(reportButton_Click);
Controls.Add(dataGridView1);
Controls.Add(reportButton);
Load += new EventHandler(Form1_Load);
Text = "DataGridViewComboBoxColumn Demo";
}
// Initializes the data source and populates the DataGridView control.
private void Form1_Load(object sender, EventArgs e)
{
PopulateLists();
dataGridView1.AutoGenerateColumns = false;
dataGridView1.DataSource = tasks;
AddColumns();
}
// Populates the employees and tasks lists.
private void PopulateLists()
{
employees.Add(new Employee("Harry"));
employees.Add(new Employee("Sally"));
employees.Add(new Employee("Roy"));
employees.Add(new Employee("Pris"));
tasks.Add(new Task(1, employees[1]));
tasks.Add(new Task(2));
tasks.Add(new Task(3, employees[2]));
tasks.Add(new Task(4));
}
// Configures columns for the DataGridView control.
private void AddColumns()
{
DataGridViewTextBoxColumn idColumn =
new DataGridViewTextBoxColumn();
idColumn.Name = "Task";
idColumn.DataPropertyName = "Id";
idColumn.ReadOnly = true;
DataGridViewComboBoxColumn assignedToColumn =
new DataGridViewComboBoxColumn();
// Populate the combo box drop-down list with Employee objects.
foreach (Employee e in employees) assignedToColumn.Items.Add(e);
// Add "unassigned" to the drop-down list and display it for
// empty AssignedTo values or when the user presses CTRL+0.
assignedToColumn.Items.Add("unassigned");
assignedToColumn.DefaultCellStyle.NullValue = "unassigned";
assignedToColumn.Name = "Assigned To";
assignedToColumn.DataPropertyName = "AssignedTo";
assignedToColumn.AutoComplete = true;
assignedToColumn.DisplayMember = "Name";
assignedToColumn.ValueMember = "Self";
// Add a button column.
DataGridViewButtonColumn buttonColumn =
new DataGridViewButtonColumn();
buttonColumn.HeaderText = "";
buttonColumn.Name = "Status Request";
buttonColumn.Text = "Request Status";
buttonColumn.UseColumnTextForButtonValue = true;
dataGridView1.Columns.Add(idColumn);
dataGridView1.Columns.Add(assignedToColumn);
dataGridView1.Columns.Add(buttonColumn);
// Add a CellClick handler to handle clicks in the button column.
dataGridView1.CellClick +=
new DataGridViewCellEventHandler(dataGridView1_CellClick);
}
// Reports on task assignments.
private void reportButton_Click(object sender, EventArgs e)
{
StringBuilder report = new StringBuilder();
foreach (Task t in tasks)
{
String assignment =
t.AssignedTo == null ?
"unassigned" : "assigned to " + t.AssignedTo.Name;
report.AppendFormat("Task {0} is {1}.", t.Id, assignment);
report.Append(Environment.NewLine);
}
MessageBox.Show(report.ToString(), "Task Assignments");
}
// Calls the Employee.RequestStatus method.
void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
// Ignore clicks that are not on button cells.
if (e.RowIndex < 0 || e.ColumnIndex !=
dataGridView1.Columns["Status Request"].Index) return;
// Retrieve the task ID.
Int32 taskID = (Int32)dataGridView1[0, e.RowIndex].Value;
// Retrieve the Employee object from the "Assigned To" cell.
Employee assignedTo = dataGridView1.Rows[e.RowIndex]
.Cells["Assigned To"].Value as Employee;
// Request status through the Employee object if present.
if (assignedTo != null)
{
assignedTo.RequestStatus(taskID);
}
else
{
MessageBox.Show(String.Format(
"Task {0} is unassigned.", taskID), "Status Request");
}
}
}