Groff mom change table background color - groff

I build some tables with groff and the mom macro package. White is the default background color. Is it possible to change the background color and text color in the table? I would like to have red in the columns 5 and 6 as background color and in the columns 7 and 8 blue as background color. Are striped colors for the columns 1-4 possible?
.TS H
center, allbox, tab(,);
c c c c c c c c
c c c c c c c c
c c c n n n n n .

I have not seen any color in groff. Afaik it only does black (text) and white (background); apart from implemented images maybe.

Related

How to exclude rows with multiple conditions and "not in" in SAS?

I have a doubt in a query, I thought the solution would be simple but I realized that it is not.
I have table A and the cod field is the main key.
COD
CATEGORY
PRODUCT
IND
SOURCE
1
Two
black
Y
ANEXO8
2
Two
black
Y
ANEXO8
3
Two
black
N
ANEXO8
4
Two
red
Y
ANEXO8
5
Two
red
Y
ANEXO8
6
Two
red
N
ANEXO8
7
Two
yellow
Y
ANEXO8
8
Two
yellow
N
ANEXO8
9
Two
green
N
ANEXO8
10
Two
green
N
ANEXO8
11
Two
pink
Y
ANEXO8
12
Two
pink
Y
ANEXO8
13
Two
pink
N
ANEXO8
14
Two
gray
N
SAS
15
Two
gray
N
SAS
16
Two
gray
N
SAS
What I am trying to get is to first filter out all rows that have the field "ANEXO8", then to exclude all rows that have the field PRODUCTequal to "black", finally to exclude all rows that have the field product equal to "red" only if the field IND is equal to "Y".
The resulting table would be equal to:
COD
CATEGORY
PRODUCT
IND
SOURCE
6
Two
red
N
ANEXO8
7
Two
yellow
Y
ANEXO8
8
Two
yellow
N
ANEXO8
9
Two
green
N
ANEXO8
10
Two
green
N
ANEXO8
11
Two
pink
Y
ANEXO8
12
Two
pink
Y
ANEXO8
13
Two
pink
N
ANEXO8
14
Two
gray
N
SAS
15
Two
gray
N
SAS
16
Two
gray
N
SAS
I have tried to perform a single query:
proc sql;
create table test as
select * from A
where SOURCE = "ANEXO8"
and PRODUCT not in ("black")
and (PRODUCT not in ("red") and IND ne "Y"));
run;
But I don't get the result I want, do you know what I could do, or maybe where am I going wrong?
Try this
proc sql;
create table test as
select * from A
where SOURCE = "ANEXO8"
and PRODUCT not in ("black")
and not (PRODUCT in ("red") and IND = "Y"));
run;
You have to be careful with how the parenthesis are actually influencing the negation
Your logic is close but the last and should be or:
create table test as
select * from A
where SOURCE = 'ANEXO8' and
PRODUCT <> 'black' and
(PRODUCT <> 'red' or IND <> 'Y');
This is simply a logic error. Do note other differences:
NOT IN seems over kill when "not equals" is sufficient.
The SQL Standard string delimiter is a single quote not a double quote.
The SQL Standard not-equals operator is <>.

Pandas Merging Data Frames Repeated Values and Values Missing

So I've created three data frames from 3 separate files (csv and xls). I want to combine the three of them into a single data frame that is 20 columns and 15 rows. I've managed to successfully do this using the code at the bottom (this is the final part of the code where I started to merge all of the existing data frames I created). However, an odd thing is happening, where the highest ranking country is duplicated 3 times, and there are two values from the 15 columns that should be there but that are missing, and I'm not exactly sure why.
I've set the index to be the same in each data frame!
So essentially my issue is that there are duplicate values showing up and other values being eliminated after I merge the data frames.
If someone could explain the mechanics to me as to why this issue is occuring I'd really appreciate it :)
***merged = pd.merge(pd.merge(df_ScimEn,df_energy[ListEnergy],left_index=True,right_index=True),df_GDP[ListOfGDP],left_index=True,right_index=True))
merged = merged[ListOfColumns]
merged = merged.sort_values('Rank')
merged = merged[merged['Rank']<16]
final = pd.DataFrame(merged)***
***Example: a shorter version of what is happening
expected:
A B C D J K L R
1 x y z j a e c d
2 b c d l a l c d
3 j k e k a m c d
4 d k c k a n h d
5 d k j l a h c d
generated after I run the code above: (the 1 is repeated and the 3 is missing)
A B C D J K L R
1 x y z j a b c d
1 x y z j a b c d
1 x y z j a b c d
4 d k c k a b h d
5 d k j l a h c d***
***Example Input
df1 = {[1:A,B,C],[2:A,B,C],[3:A,B,C],[4:A,B,C],[5:A,B,C]}
df2 = {[1:J,K,L,M],[2:J,K,L,M],[3:J,K,L,M],[4:J,K,L,M],[5:J,K,L,M]}
df3 = {[1:R,E,T],[2:R,E,T],[3:R,E,T],[4:R,E,T],[5:R,E,T]}
So the indexes are all the same for each data frame and then some have a
different number of rows and different number of columns but I've edited them
to form the final data frame. and each capital letter stands for a column
name with different values for each column***

stop pandas from renaming columns with same name so i can use wide to long

I have an excel file that im reading into pandas that looks similar to this
name size color material size color material size color material
bob m red coton m yellow cotton m green dri-fit
james l green dri-fit l green cotton l red cotton
steve l green dri-fit l green cotton l red cotton
I want to tally all my shirt types into something like this
l green dri-fit 2
l red coton 2
m red coton 1
i am using pandas ExcelFile to read the file into a file object, then using parse to parse the sheet into a dataframe.
import pandas as pd
file = pd.ExcelFile('myexcelfile.xlsx')
df = file.parse('sheet1')
To try and get to my desired output, I am trying to use Wide to Long. The problem is, because some of my columns have the same names, when I read the file into pandas its renaming my columns. The second instance of size, for example, turns automatically into size.2, same with color and material. If i try to use stubnames with wide to long, it complains that the first instance of size ... "stubname cant be identical to a column name".
Is there any way to use wide to long prior to pandas renaming my columns?
The column numbering is problematic for pd.wide_to_long, so we need to modify the first instance of the column names, adding a .0, so they don't conflict with the stubs.
Sample Data
import pandas as pd
df = pd.read_clipboard()
print(df)
name size color material size.1 color.1 material.1 size.2 color.2 material.2
0 bob m red coton m yellow cotton m green dri-fit
1 james l green dri-fit l green cotton l red cotton
2 steve l green dri-fit l green cotton l red cotton
Code:
stubs = ['size', 'color', 'material']
d = {x: f'{x}.0' for x in stubs}
df.columns = [d.get(k, k) for k in df.columns]
res = pd.wide_to_long(df, i='name', j='num', sep='.', stubnames=stubs)
# size color material
#name num
#bob 0 m red coton
#james 0 l green dri-fit
#steve 0 l green dri-fit
#bob 1 m yellow cotton
#james 1 l green cotton
#steve 1 l green cotton
#bob 2 m green dri-fit
#james 2 l red cotton
#steve 2 l red cotton
res.groupby([*res]).size()
#size color material
#l green cotton 2
# dri-fit 2
# red cotton 2
#m green dri-fit 1
# red coton 1
# yellow cotton 1
value_counts
cols = ['size', 'color', 'material']
s = pd.value_counts([*zip(*map(np.ravel, map(df.get, cols)))])
(l, red, cotton) 2
(l, green, cotton) 2
(l, green, dri-fit) 2
(m, green, dri-fit) 1
(m, yellow, cotton) 1
(m, red, coton) 1
dtype: int64
Counter
And more to my liking
from collections import Counter
s = pd.Series(Counter([*zip(*map(np.ravel, map(df.get, cols)))]))
s.rename_axis(['size', 'color', 'material']).reset_index(name='freq')
size color material freq
0 m red coton 1
1 m yellow cotton 1
2 m green dri-fit 1
3 l green dri-fit 2
4 l green cotton 2
5 l red cotton 2
CODE BELOW:
df = pd.read_excel('C:/Users/me/Desktop/sovrflw_data.xlsx')
df.drop('name', axis=1, inplace=True)
arr = df.values.reshape(-1, 3)
df2 = pd.DataFrame(arr, columns=['size','color','material'])
df2['count']=1
df2.groupby(['size','color','material'],as_index=False).count()

How to position color bar in GrADS?

I am looking for a code which positions the color bar by itself. Here is graph:
I used the set_pareas.gs script to fix the graphs in columns and color.gs script to color the plots. The color bar script is xcbar.gs. Here are the command lines
c
set_parea 1 3 1 1 -margin 0.8
color 0 12 1.2 -kind red->orange->yellow->dodgerblue->blue
d var1
set_parea 1 3 1 2 -margin 0.8
color 0 12 1.2 -kind red->orange->yellow->dodgerblue->blue
d var2
set_parea 1 3 1 3 -margin 0.8
color -12 12 2.4 -kind blue->white->red
d var1-var2
I would like that the color bar stay just below the differences map and red->orange->yellow->dodgerblue->blue color bar stay just below the orange maps.
You can adjust the position of color bar in the command of xcbar.
The below document maybe necessary for you:
http://kodama.fubuki.info/wiki/wiki.cgi/GrADS/script/xcbar.gs?lang=en

Fill in rows missing row labels for repeated values

I have the following input:
printf "Name\tArea\tNumber\tA\tB\tC\n\t\t\tA\tB\tC\n\t\t\tA\tB\tC\n"
Name Area Number A B C
A B C
A B C
If first 3 columns are blank,
I want to print the previous 3 columns along with the data of the new line,
else print the line as is. Output should look like this:
printf "Name\tArea\tNumber\tA\tB\tC\nName\tArea\tNumber\tA\tB\tC\nName\tArea\tNumber\tA\tB\tC\n"
Name Area Number A B C
Name Area Number A B C
Name Area Number A B C
My interpretation of the question is that fields 1 to 3 can appear anywhere in the file, with values possibly different from the ones they had previously. So the idea would be to reproduce the last fields 1 to 3 seen so far, so that the input:
Name Area Number A B C
A B D
F G T
Nam Zig BBA U Z x
A B D
would produce the output:
Name Area Number A B C
Name Area Number A B D
Name Area Number F G T
Nam Zig BBA U Z x
Nam Zig BBA A B D
So I propose:
awk 'BEGIN {FS=OFS="\t"; hd1=hd2=hd3=""} $1=="" {$1=hd1;$2=hd2;$3=hd3; print; next} {hd1=$1;hd2=$2;hd3=$3; print}' yourfile
ok, I only checked the non-nullity of $1, but we could easily adapt to add only the missing fields.
I would solve this as a fixed width problem. A GNU awk solution:
$ awk '$1~/^ +$/{sub($1,h)}{h=$1}1' FIELDWIDTHS=23 file
Name Area Number A B C
Name Area Number A B D
Name Area Number F G T
Nam Zig BBA U Z x
Nam Zig BBA A B D
Just change the FIELDWIDTHS variable to match your data as needed.
The other more verbose approach is to iterate over each of the fields that could be missing:
$ awk '{for(i=1;i<=c;i++)if($i=="")$i=h[i]}{for(i=1;i<=c;i++)h[i]=$i}1' c=3 FS='\t' OFS='\t' file
Name Area Number A B C
Name Area Number A B D
Name Area Number F G T
Nam Zig BBA U Z x
Nam Zig BBA A B D
Just change c to the value of missing columns you want to check.