-
Notifications
You must be signed in to change notification settings - Fork 368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Show group values when printing grouped dataframe #1632
Changes from 3 commits
1b2798d
ff0b463
84ff9ba
2762f10
461d345
8a6301d
3978895
43e8378
085e672
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,31 +6,55 @@ function Base.show(io::IO, gd::GroupedDataFrame; | |
rowlabel::Symbol = :Row, | ||
summary::Bool = true) | ||
N = length(gd) | ||
keys = join(':' .* string.(names(gd.parent)[gd.cols]), ", ") | ||
grouped_names = names(gd.parent)[gd.cols] | ||
keys = join(':' .* string.(grouped_names), ", ") | ||
|
||
keystr = length(gd.cols) > 1 ? "keys" : "key" | ||
groupstr = N > 1 ? "groups" : "group" | ||
summary && print(io, "$(typeof(gd)) with $N $groupstr based on $keystr: $keys") | ||
if allgroups | ||
for i = 1:N | ||
nrows = size(gd[i], 1) | ||
rows = nrows > 1 ? "rows" : "row" | ||
print(io, "\nGroup $i: $nrows $rows") | ||
|
||
grouped_values = [first(gd[i][col]) for col in gd.cols] | ||
|
||
print(io, "\nFirst Group: $nrows $rows") | ||
|
||
for (name, value) in zip(grouped_names, grouped_values) | ||
print(io, "\n:$(name) => $value") | ||
end | ||
|
||
show(io, gd[i], summary=false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we shouldn't print the grouping columns, since they're listed above? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it reads well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As you like. But just to make sure we're talking about the same thing: I was suggesting we could drop the grouping columns from the data frame we print below, since all values are equal within a given group. |
||
allrows=allrows, allcols=allcols, rowlabel=rowlabel) | ||
end | ||
else | ||
if N > 0 | ||
nrows = size(gd[1], 1) | ||
rows = nrows > 1 ? "rows" : "row" | ||
|
||
grouped_values = [first(gd[1][col]) for col in gd.cols] | ||
|
||
print(io, "\nFirst Group: $nrows $rows") | ||
|
||
for (name, value) in zip(grouped_names, grouped_values) | ||
print(io, "\n:$(name) => $value") | ||
end | ||
|
||
show(io, gd[1], summary=false, | ||
allrows=allrows, allcols=allcols, rowlabel=rowlabel) | ||
end | ||
if N > 1 | ||
print(io, "\n⋮\n") | ||
nrows = size(gd[N], 1) | ||
rows = nrows > 1 ? "rows" : "row" | ||
print(io, "Last Group: $nrows $rows") | ||
|
||
grouped_values = [first(gd[N][col]) for col in gd.cols] | ||
|
||
print(io, "\nFirst Group: $nrows $rows") | ||
for (name, value) in zip(grouped_names, grouped_values) | ||
print(io, "\n:$(name) => $value") | ||
end | ||
|
||
show(io, gd[N], summary=false, | ||
allrows=allrows, allcols=allcols, rowlabel=rowlabel) | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.