My effort so far is minimal. In fact i don't know to approach it using pandas.
I got a list of even numbers and odd numbers and I need to split the list and paste it in adjacent column and do a concatenate command over the list.
for example my list reads:
odd even
1 2
3 4
5 6
7 8
9 10
11 12
13 14
15 16
17 18
19 20
So I split the column exactly into two and concatenate using excel concatenate command
Expected result:
odd-odd even-even
111 212
313 414
515 616
717 818
919 1020
Help!
Minimal working code:
import pandas as pd
list2=[1,3,5,7,9,11,13,15,17,19]
df = pd.DataFrame((list2), columns=['odd'])
df = df.astype(str).groupby(df['odd'].astype(str).str[-1]).agg({"odd": lambda x: "".join(x)}).reset_index(drop=True)
print (df)
Output got:
odd
0 111
1 313
2 515
3 717
4 919
But when I add more values to list example: list2=[1,3,5,7,9,11,13,15,17,19,21,23,25,27] i get
odd
0 11121
1 31323
2 51525
3 71727
4 919
what i am looking for is:
115
317
519
721
923
1125
1327
This does it. Thanks to everyone for your effort.
import pandas as pd
list2=[1,3,5,7,9,11,13,15,17,19,21,23,25,27]
df = pd.DataFrame((list2), columns=['odd'])
n2 = len(df)
n1 = int(n2/2)
df2 = pd.DataFrame()
df2['odd-odd'] = df.odd[0:n1].astype(str).to_numpy()+df.odd[n1:n2].astype(str).to_numpy()
print (df2['odd-odd'])