Excel formula to separate text between "\" - excel

I have a path in
A1 C:\Users\fe\Desktop\01 Tur\2015\Kauk\Telu\Frame Report.pdf
A2 C:\Users\fe\Desktop\01 Tur\Deliveries\10 Toim\Alh\2005\Moot\CMC.doc
A3 C:\Users\fe\Desktop\01 Tur\Equip\Set\M-R\Kir\G3\sen.xls
etc.
I would like to separate these paths to (example for A1)
A2 "Users" | A3 "fe" | A4 "Desktop" | A5 "01 Tur" | A6 "2015" | A7 "Kauk" | A8 "Telu" | A9 "Frame Report.pdf"
I have tried to play with
=IF(ISERROR(FIND("\";A1;FIND("\";A1;1)+2));A1;LEFT(A1;FIND("\";A1;FIND("\";A1;1)+2)))
but it is not so suitable for multiplication. Is there any better solution that can be copied for this case?

With data in A1, in B1 enter:
=TRIM(MID(SUBSTITUTE($A1,"\",REPT(" ",999)),COLUMNS($A:A)*999-998,999))
and copy across:

Related

Increment row reference based on index in selection, and not same row number between sheets

I have a workbook containing two sheets. Sheet 1 has values in column A for every row up to row number 2000. Sheet 2 should duplicate the values over multiple rows for each row in Sheet 1. Like this:
Sheet1:
a1 | 123
a2 | 456
a3 | 789
and for Sheet2:
Sheet2:
a1 | 123
a2 | 123
a3 | 456
a4 | 456
a5 | 789
a6 | 789
The duplication is fairly simple, where I just put a reference of the next rows to the row collecting the row value from Sheet1:
a2: =a1
However, selecting and dragging rows a1 and a2 in Sheet2 to get the corresponding formulas copied over to the next rows, the formula does not reference the correct rows in Sheet1. Something like this occurs:
Sheet2:
a1 | 123
a2 | 123
a3 | 789
a4 | 789
Where cell a3 in Sheet2 references cell a3 in Sheet1, instead of cell a2 which is the next row. I have tried several functions with index, offset etc. but none of them seem to circumvent the automatic same-row-reference between the worksheets. Any quick ideas?
"generic approach" imho is either one of these.. :
Just edit the "2" in the 1st comment ans.
use ROW() and argument for OFFSET()
'Manually' build the reference using INDIRECT
set the 1st 2 row manually, 3rd row onward use =IF(A2=A1,INDIRECT("Sheet1!A"&(row()+1)/2,TRUE),A2) and drag downwards.
Is this what you are looking for?

How to split every row in dataframe into two with some features? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have this dataframe:
A C1 C2
a1 c1 c3
a2 c2 c4
And columns C1 and C2 has the same type.
And I want get this:
A C
a1 c1
a1 c3
a2 c2
a2 c4
How I can do this?
UPD:
In answers I get this info:
df_final = df.set_index('A').stack().droplevel(1).rename('C').reset_index()
Out[604]:
A C
0 a1 c1
1 a1 c3
2 a2 c2
3 a2 c4
But what I should if I want split in this way?
A B C1 C2 C3 C4
a1 b1 c1 c2 c3 c4
a2 b2 c5 c6 c7 c8
and get this:
A B C1 C2
a1 b1 c1 c2
a1 b1 c3 c4
a2 b2 c5 c6
a2 b2 c7 c8
Edit 2: If you have even number of columns Cx, you may use numpy to make it simple
import numpy as np
cols = ['C1','C2','C3','C4']
df1 = df.loc[df.index.repeat(len(cols) / 2), ['A','B']].reset_index(drop=True)
df_final = df1.join(pd.DataFrame(df[cols].to_numpy().reshape(-1,2), columns=['C1','C2']))
Out[698]:
A B C1 C2
0 a1 b1 c1 c2
1 a1 b1 c3 c4
2 a2 b2 c5 c6
3 a2 b2 c7 c8
Edit for updated sample:
On multiple columns Cx splitting by 2, you need wide_to_long. However, beforing doing it, you need pre-processing columns names to appropriate format to use with wide_to_long
df1 = df.set_index(['A','B'])
stub_cols = (np.arange(df1.columns.size) % 2).astype(str)
suff_cols = (np.arange(df1.columns.size) // 2).astype(str)
d = dict(zip(stub_cols, ['C1', 'C2']))
df1.columns = pd.Series(stub_cols) + '_' + suff_cols
df_final = pd.wide_to_long(df1.reset_index(),
i=['A','B'],
j='num',
stubnames=['0','1'],
sep='_').droplevel(-1).rename(d, axis=1).reset_index()
Out[680]:
A B C1 C2
0 a1 b1 c1 c2
1 a1 b1 c3 c4
2 a2 b2 c5 c6
3 a2 b2 c7 c8
Give this a try
df_final = df.set_index('A').stack().droplevel(1).rename('C').reset_index()
Out[604]:
A C
0 a1 c1
1 a1 c3
2 a2 c2
3 a2 c4
print(
pd.concat([df.A, df[['C1', 'C2']].apply(list, axis=1)], axis=1).explode(0).rename(columns={0:'C'})
)
Prints:
A C
0 a1 c1
0 a1 c3
1 a2 c2
1 a2 c4

Linux sort combining -V and -f

I want to combine sort -V and -f. Is there a way?
Here is simple example. I want to sort this list.
> cat testme
a1
a2
a11
a12
a3
A8
B8
b1
b11
Default sort is upper case first, lower case second, plus a11 comes before a2
> cat testme | sort
A8
B8
a1
a11
a12
a2
a3
b1
b11
I use -V which is awesome, a2 is before a11, but its still upper case then lower case
> cat testme | sort -V
A8
B8
a1
a2
a3
a11
a12
b1
b11
I can sort -f which fixes case, but a11 is still before a2
>cat testme | sort -f
a1
a11
a12
a2
a3
A8
b1
b11
B8
I try and combine them but -V wins and -f loses.
>cat testme | sort -f -V
A8
B8
a1
a2
a3
a11
a12
b1
b11
Is there an option to combine these?
Desired output is:
a1
a2
a3
A8
a11
a12
b1
B8
b11
Version in use:
[03:11:09] sa-hq1:~ # sort --version
sort (GNU coreutils) 8.4
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
On my Fedora 25, it works properly.
[root#localhost ~]# sort --version
sort (GNU coreutils) 8.25
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Mike Haertel and Paul Eggert.
[root#localhost ~]# sort -Vf testme
a1
a2
a3
A8
a11
a12
b1
B8
b11
[root#localhost ~]#
You no need to cat file to sort command. It can read a file from stdin or from argument list:
sort -Vf file
or
sort -Vf < file
test:
~ > sort -Vf < file
a1
a2
a3
A8
a11
a12
b1
B8
b11
~ > sort -Vf file
a1
a2
a3
A8
a11
a12
b1
B8
b11
~ >

Sum fields in a column if there is an entry in a corresponding row in another column

Assume the following data:
| A B C
--+------------------------
1 | 2 3 5
2 | 2 3
3 | 4 4
4 | 2 3
5 | 5 6
In cell A6, I want Excel to add cells C1, C2, C3 on the basis that A1, A2 and A3 have data in. Similarly, I want B6 to add together C1, C4 and C5 because B1, B4 and B5 have data.
Can someone help?
In A6 enter:
=SUMPRODUCT(($C1:$C5)*(A1:A5<>""))
and then copy to B6:
A simple SUMIF formula will work
=SUMIF(A$1:A$5,"<>",$C$1:$C$5)
Place that formula is cell A6 and then copy it to B6.
You can create another column, e.g. AValue, with the formula =IF(ISBLANK(A1),0,A1) in it. This will return 0 if the cell in A in the corresponding line is empty, or the value from the cell in A otherwise.
Then you can just sum up the values of the new column.

copy cell to selected date range

I have a list of dates in B2:GF2. I enter 2 dates - "A1 start date and B1 End date". I also enter a value (number) in cell C1. The value in C1 should be copied to all the cells under the list of dates from A2:GF2 between the dates choosed in A1 and B1. Let the copied value between the row A3:GF3.
E.g.:
A | B | C
Row1 3/3/2015| 5/5/2015 | ABC
Row2 2/2/2015 | 3/3/2015 | 4/4/2015 | 4/23/2015 | 5/5/2015....
ABC ABC ABC ABC
In cell C4, type =IF(AND(C3>=$A$2,C3<$B$2),$C$2,""), then just copy cell C4 across.

Resources