Python Forum
sort values of a column pandas - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: sort values of a column pandas (/thread-21930.html)



sort values of a column pandas - karlito - Oct-21-2019

Hi,

I'm trying to sort a df looking like this into 2 dfs. Any help! Thks

              A                          pos                  neg
index                         index                index  
01.01.19      0    -> new     01.01.19   0         03.01.19   -1
02.01.19      1               02.01.19   1         12.01.19   -2
03.01.19     -1               14.01.19   3         
12.01.19     -2               31.01.19   1
14.01.19      3               
31.01.19      1        
Thks


RE: sort values of a column pandas - aankrose - Oct-21-2019

D = pd.read_csv('sort.csv')
E = pd.DataFrame(D)
print(E[E['A'] < 0])
print(E[E['A'] > 0])



RE: sort values of a column pandas - karlito - Oct-22-2019

(Oct-21-2019, 04:24 PM)aankrose Wrote:
D = pd.read_csv('sort.csv')
E = pd.DataFrame(D)
print(E[E['A'] < 0])
print(E[E['A'] > 0])

Thks aankrose ...
I was trying to make thnings complicated like this
for col in df:
   if df['col'] > 0:
      df['pos'] = df['col']
   else:
      df['neg'] = df['col']
return df