我有一个由 231840 行组成的数据框。我需要将其分成 161 个单独的表,每个表包含 1440 行,即第一个表包含前 1440 行,第二个表包含接下来的 1440 行,依此类推,直到我得到 161 个单独的表,行数组合为231840 行。有任何想法吗?
这应该是一个需要解决的简单问题,但我无法获得我想要的确切输出。我有一个嵌套的数据帧列表,我想过滤掉所有少于 50 行的数据帧,并将它们从列表中删除。
这是我尝试过的可重现的示例 -
L <- list(iris,mtcars,iris)
O <- list(iris,mtcars,iris)
H <- list(iris,mtcars,iris)
List <- list(L,O,H)
test <- lapply(List, function(x) lapply(x, function(x) if (nrow(x)<50) NULL else x)))
Run Code Online (Sandbox Code Playgroud)
这适用于第一个列表,但它用 NULL 替换嵌套列表中的 mtcars 数据帧 - 它不会将它们从列表中删除。不幸的是,它不会循环其他列表。我也尝试过使用过滤功能
test <- lapply(List, function(x) lapply(x, function(x) filter(x, nrow(x)>50)))
Run Code Online (Sandbox Code Playgroud)
这与不循环所有列表有同样的问题,对于第一个列表,它给我留下了一个空的 df ,它仍然是列表的一个元素。我的最后一个解决方案是编写一个 for 循环,我在嵌套中的第一个列表上尝试了它,这基本上有效 - 但如果可能的话,我想找到一种不太笨重的方法来做到这一点。这也会返回一个错误:Error in List[[1]][[ii]] : subscript out ofbounds
for (ii in seq_along(List[[1]])){
n_rows = nrow(List[[1]][[ii]])
if (n_rows < 20){
List[[1]][[ii]] = NULL
}
}
Run Code Online (Sandbox Code Playgroud)
我希望有一个简单的解决方案即将出现!
我正在使用以下代码,它计算每个子组的 z 分数。我想在最后添加一列,对 z 分数进行求和,从而对以“_zscore”结尾的所有列中的所有值进行逐行求和。我如何具体选择这些列?
(请注意,我的真实数据有更多列,因此我希望在列名称中专门选择“_zscore”。)
library(dplyr)
set.seed(12345)
df1 = data.frame(a=c(rep("a",8), rep("b",5), rep("c",7), rep("d",10)),
b=rnorm(30, 6, 2),
c=rnorm(30, 12, 3.5),
d=rnorm(30, 8, 3)
)
df1_z <- df1 %>%
group_by(a) %>%
mutate(across(b:d, list(zscore = ~as.numeric(scale(.)))))
Run Code Online (Sandbox Code Playgroud) 我有两个数据框,df1 和 df2。现在,df1 包含 6 条记录,df2 包含 4 条记录。我想从中找出无与伦比的记录。我尝试过,但出现错误,ValueError: Can only compare identically-labelled DataFrame objects我猜这是由于 df 的长度造成的,因为 df1 有 6 个,df2 有 4 个,但是我如何比较它们并获取不匹配的行?
代码
df1=
a b c
0 1 2 3
1 4 5 6
2 3 5 5
3 5 6 7
4 6 7 8
5 6 6 6
df2 =
a b c
0 3 5 5
1 5 6 7
2 6 7 8
3 6 6 6
index = (df != …Run Code Online (Sandbox Code Playgroud) 如何在asp.net(C#)表的行和列之间绘制边框?
我有以下内容:
<asp:Table ID="Table1" runat="server" BackColor="White" BorderColor="Black"
BorderWidth="1px" ForeColor="Black">
</asp:Table>
Run Code Online (Sandbox Code Playgroud)
在codebehind文件中我添加行:
for (int i = 0; i < games.Count(); i++)
{
TableRow tr = new TableRow();
for (int j = 0; j < 9; j++)
{
TableCell tc = new TableCell();
tc.Text = games[i].getData(j);
tr.Cells.Add(tc);
}
tr.BorderWidth = 1;
tr.BorderColor = Color.Black;
Table1.Rows.Add(tr);
}
Run Code Online (Sandbox Code Playgroud)
但是,II没有看到表格的行和列之间有任何边界.该表是:

那么,如何在asp.net表的行和列之间绘制边框?
我需要在表中保留用户的最后5个搜索结果.
我写了一个脚本来删除其他行,但它不起作用:
DELETE FROM
SELECT
ROW_NUMBER () OVER (ORDER BY search_time DESC) AS row_number;
FROM
history_user
WHERE
user_id = 188
WHERE row_number>5
Run Code Online (Sandbox Code Playgroud)
我做错了什么?
我有一个带有自动过滤器的excel表.
在过滤后的表中,我只过滤了几行.
我的目标是icterate所有可见行,以收集数据以复制到另一张表.
我想要一种方法来收集带有fisrt可见行号的变量.
我的草案代码是:
Dim cnp As String
Dim nome As String
Dim filter_rng As Range
Dim rw As Range
Dim last_row As Long 'last visible data row
Dim dest_row As Long 'row to paste the colected data
Set filter_rng = Range("A5:Y" & last_row).Rows.SpecialCells(xlCellTypeVisible)
'collect data
For Each rw In filter_rng.SpecialCells(xlCellTypeVisible)
workshett(1).Activate
cnp = Range("a" & rw).Value
nome = Range("b" & rw).Value
'copy data to another worksheet first data line is cell A2
Worksheet(2).Activate
Range("A" & dest_row + 1).Value …Run Code Online (Sandbox Code Playgroud) 我正在学习使用python而且我坚持使用这段代码.
我想显示行,但我得到列.我尝试了不同的变化,我为while循环得到一行,但我仍然得到for循环的列.
Start_num = 0
Max_num = 200
while Start_num < 201:
for Number in range (Max_num, -1, -25):
print(Start_num, end=' ')
Start_num += 25
print(Number)
Run Code Online (Sandbox Code Playgroud)
这是输出当前查找此代码的方式.
0 200
25 175
50 150
75 125
100 100
125 75
150 50
175 25
200 0
Run Code Online (Sandbox Code Playgroud)
必须有一种方法来获得两行而不是列,请帮忙.
我有一个看起来像这样的数据框
ID Date Period Account Amount1 Amount2
<chr> <chr> <chr> <chr> <chr> <chr>
1 76311099 43494 /1 P / ABC / 123456 NA 3116362
2 NA NA NA C100ST NA NA
3 66112599 37135 /26 S / ADR NA 1246880.3900000001
4 NA NA NA 65101599 / S0 NA NA
5 45461599 37155 /O6 B / INR / REVERSE NA 623440.19000000006
6 NA NA NA UNDO / S0 NA NA
7 69876599 37134 /O3 N / ABC 401.63 NA
8 19991099 …Run Code Online (Sandbox Code Playgroud) 我有TLSWL大约20,000行的数据框(称为)。我Time在df中有一列,我需要删除所有在特定分钟内结束的行。我只需要增加30分钟的时间即可匹配其他数据进行比较。
这是我目前正在使用的:
TLSWL<- TLSWL[TLSWL$Time != "0:06"&TLSWL$Time !="0:12"&TLSWL$Time
!="0:18"&TLSWL$Time !="0:24"&TLSWL$Time != "0:36"&TLSWL$Time
!="0:42"&TLSWL$Time !="0:48"&TLSWL$Time != "0:54"&TLSWL$Time
!= "1:06"&TLSWL$Time != "1:12"&TLSWL$Time != "1:18"&TLSWL$Time
!= "1:24"&TLSWL$Time != "1:36"&TLSWL$Time != "1:42"&TLSWL$Time
!= "1:48"&TLSWL$Time != "1:54"&TLSWL$Time != "2:06"&TLSWL$Time
!= "2:12"&TLSWL$Time != "2:18"&TLSWL$Time != "2:24"&TLSWL$Time
!= "2:36"&TLSWL$Time != "2:42"&TLSWL$Time != "2:48"&TLSWL$Time
!= "2:54"&TLSWL$Time != "3:06"&TLSWL$Time != "3:12"&TLSWL$Time
and so on all the way to the times in 24:xx
Run Code Online (Sandbox Code Playgroud)
它适用于较小的数据帧,而不是在军事时间,但是您可以看到以这种方式进行操作所需的代码行最终会变得很长。
可以更有效地做到这一点吗?