The `column` utility without the -t option - linux

After reading the man pages for column and trying a few examples, I wonder: what does this command do when it is not supplied the -t option?

It takes lines and puts them on separate cell inside a table, filling rows first:
$ seq 40 | column
1 4 7 10 13 16 19 22 25 28 31 34 37 40
2 5 8 11 14 17 20 23 26 29 32 35 38
3 6 9 12 15 18 21 24 27 30 33 36 39
It's similar to ls output, but the separator is tab between columns, while ls uses spaces:
$ ls
a ab ad af ah aj al an ap ar at av ax az c e g i k m o q s u w y
aa ac ae ag ai ak am ao aq as au aw ay b d f h j l n p r t v x z
$ printf "%s\n" * | column
a ac af ai al ao ar au ax b e h k n q t w z
aa ad ag aj am ap as av ay c f i l o r u x
ab ae ah ak an aq at aw az d g j m p s v y
If you have some newline-separated data that you want to represent in a condensed form in a nicely indented table, column is the way to go.

Related

Pandas columns to rows transformation not working?

We have below pandas dataframe
and we need to convert into below dataframe
while using pd.wide_to_long command we are getting below error:-
ValueError: stubname can't be identical to a column name
This command is being use:-
pd.wide_to_long(df,['Org','City'],i=['First Name','Middle Name','Last Name','Years'],j='drop').reset_index(level=[0,1]
For me your solution working, also added parameter stubnames. Mayb eit is bug in oldier pandas version, link, so you can try to upgrade pandas to last version:
df = pd.wide_to_long(df, stubnames=['Org','City'],
i=['First Name','Middle Name','Last Name','Years'],
j='drop').reset_index().drop('drop', 1)
print (df)
First Name Middle Name Last Name Years Org City
0 aa cc dd 2019 v n
1 aa cc dd 2019 m m
2 aa cc dd 2019 d n
3 aa cc dd 2019 p j
4 zz yy xx 2018 p n
5 zz yy xx 2018 q n
6 zz yy xx 2018 i d
7 zz yy xx 2018 NaN NaN
EDIT: If possible some duplicates in data is possible create default index by reset_index and add column index to i variables:
print (df)
First Name Middle Name Last Name Years Org0 Org1 Org2 Org3 City0 City1 \
0 aa cc dd 2019 v m d p n m
1 zz yy xx 2018 p q i NaN n n
City2 City3
0 n j
1 d NaN
df = pd.wide_to_long(df.reset_index(), stubnames=['Org','City'],
i=['index','First Name','Middle Name','Last Name','Years'],
j='drop').reset_index().drop(['drop', 'index'], 1)
print (df)
First Name Middle Name Last Name Years Org City
0 aa cc dd 2019 v n
1 aa cc dd 2019 m m
2 aa cc dd 2019 d n
3 aa cc dd 2019 p j
4 zz yy xx 2018 p n
5 zz yy xx 2018 q n
6 zz yy xx 2018 i d
7 zz yy xx 2018 NaN NaN

Pandas Transform and add second line between the measurements

I am struggeling with transforming a pandas dataframe.
df=
0 A -- cm
1 B -- cm2
2 C 69 cm/s
3 D 48 cm/s
4 E 152 ms
5 F 1.05 NaN
6 G 9.15 NaN
7 H -- ms
8 I 8 cm/s
9 J 12 cm/s
I want to transform it to:
> A A_Unit B B_Unit C C_Unit ...
> -- cm -- cm2 69 cm/s ...
A to J is a parameter.
Conversion to a dataframe with only numbers works very good with df.T.drop(0), but i have actually no clue, how to add the label of the units it's values next to the parameter columns.
Maybe someone has a good idea and might help me with this topic.
Thanks
Thomas
You can stack and transpose since you will always have groupings of two.
u = df.set_index(0).stack().to_frame().T
u.columns = [
x if y == 1 else f'{x}_Unit' for x, y in u.columns]
A A_Unit B B_Unit C C_Unit D D_Unit E E_Unit F G H H_Unit I I_Unit J J_Unit
0 -- cm -- cm2 69 cm/s 48 cm/s 152 ms 1.05 9.15 -- ms 8 cm/s 12 cm/s
IIUC:
df = pd.read_clipboard(sep='\s\s+', header=None)
df_out = df.set_index(1).drop(0, axis=1).rename(columns={2:'',3:'Unit'}).stack()
df_out = df_out.to_frame().T
df_out.columns = [f'{i}_{j}' if j else f'{i}' for i, j in df_out.columns]
df_out
Output:
A A_Unit B B_Unit C C_Unit D D_Unit E E_Unit F G H \
0 -- cm -- cm2 69 cm/s 48 cm/s 152 ms 1.05 9.15 --
H_Unit I I_Unit J J_Unit
0 ms 8 cm/s 12 cm/s

Excel formula - If A=1 B=2.......Z=26. If you input CAT in cell it should display the result 24

Excel formula - If A=1 B=2.......Z=26. If you input CAT in cell it should display the result 24 ie C+A+T. Not VB or JAVA or any programming language just the excel formula.
This is what I tried
=SUM(LOOKUP({"C","A","T"},B3:B28,C3:C28))
with input of below in the cells B3:B28,C3:C28. I want the result to display when I put in CAT in the cell.
A 1
B 2
C 3
D 4
E 5
F 6
G 7
H 8
I 9
J 10
K 11
L 12
M 13
N 14
O 15
P 16
Q 17
R 18
S 19
T 20
U 21
V 22
W 23
X 24
Y 25
Z 26
Use SUMPRODUCT to iterate the letters and use CODE to return the value:
=SUMPRODUCT(CODE(UPPER(MID(A1,ROW($XFD$1:INDEX($XFD:$XFD,LEN(A1))),1)))-64)

Generating AA, AB, ..., ZZ in excel using numbers 0-25

I have created column as mentioned below:
0 A 00
1 B 01
2 C 02
3 D 03
4 E 04
5 F 05
6 G 06
7 H 07
8 I 08
9 J 09
10 K 010
I have two columns , first column has 0-10 and second column has A-K and I have created a new column with combinations of AA , AB till ZZ in numbers as in 00 , 01 till 010. I need to substitute the number with the alphabets using vlookup and if condition . Kindly help me with it
Can I do it with help of =Vlookup() and/or =If() condition alone?
Sorry, not really sure what you're after, I can't read your initial starting data very clearly ?
To replace a value, you can:
=SUBSTITUTE(A1,"0","A")
not sure if that does what you want, though?
I'll start a new answer, it's different enough from the first post.
So, taking your initial data:
I add 2 more columns: It's simply the mapping of Column C, split out into column D and E. At time of writing this, I have no idea how you translate that programatically, so until we have the rules, I'll just do this . and we can plug that other part in later.
0 A 00 0 0
1 B 01 0 1
2 C 02 0 2
3 D 03 0 3
4 E 04 0 4
5 F 05 0 5
6 G 06 0 6
7 H 07 0 7
8 I 08 0 8
9 J 09 0 9
10 K 010 0 10
And then use this formula:
=CONCATENATE(VLOOKUP(D1,$A$1:$B$11,2,FALSE),VLOOKUP(E1,$A$1:$B$11,2,FALSE))
and you'll end up with this:
AA
AB
AC
AD
AE
AF
AG
AH
AI
AJ
AK
If your ultimate goal is to generate AA thru ZZ, first enter the following UDF in a standard module:
Public Function BumpString(s As String) As String
Dim aryIN(1 To 1000) As Integer
Dim L As Long, i As Long, carry As Boolean
L = Len(s)
j = 1
For i = L To 1 Step -1
aryIN(j) = Asc(Mid(s, i, 1))
j = j + 1
Next i
For i = 1 To L
carry = False
aryIN(i) = aryIN(i) + 1
If aryIN(i) = 91 Then
aryIN(i) = 65
carry = True
Else
Exit For
End If
Next
If carry Then
L = L + 1
aryIN(L) = 65
End If
For i = 1 To L
BumpString = Chr(aryIN(i)) & BumpString
Next i
End Function
Then pick a cell, say D1 and enter AABelow it enter:
=bumpstring(D1)
Then copy D2 down thru D676
You don't need VLOOKUP for this.
You can use the CODE function with the first and last character:
=(CODE(LEFT(A1))-65) & (CODE(RIGHT(A1))-65)
Note that many combinations will map to the same number, such as "BU" and "MA":

Why does this not work EXCEL 2010

a 1 Offset 4
b 2 message h e l l o
c 3 Value 8 5 12 12 15
d 4 Encrypted value 12 9 16 16 19
e 5 Encrypted letter #N/A #N/A #N/A #N/A #N/A
f 6
g 7
h 8
i 9
j 10
k 11
l 12
m 13
n 14
o 15
p 16
q 17
r 18
s 19
t 20
u 21
v 22
w 23
x 24
y 25
z 26
The task is to take the set value of the letter and add the offset too it and then put the encrypted letters in the encrypted letter cell. But I keep getting this #N/A error the formula I used is:
=VLOOKUP(F4,$A$1:$B$26,2,FALSE)
link to screenshot: http://i1370.photobucket.com/albums/ag263/dylanevs/excel_zps3f61ed50.jpg
I believe you need to swap your columns.
Vlookup looks for the value in the first column, and returns a cell to the right (in your formula, the second column).
The reason for the #N/A is it's looking for an exact match for a number, in a range that only contains letters.

Resources