Python Forum
sort values of a column pandas
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
sort values of a column pandas
#1
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
Reply
#2
D = pd.read_csv('sort.csv')
E = pd.DataFrame(D)
print(E[E['A'] < 0])
print(E[E['A'] > 0])
Reply
#3
(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 
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Find duplicates in a pandas dataframe list column on other rows Calab 2 1,924 Sep-18-2024, 07:38 PM
Last Post: Calab
  Find strings by index from a list of indexes in a different Pandas dataframe column Calab 3 1,540 Aug-26-2024, 04:52 PM
Last Post: Calab
  attempt to split values from within a dataframe column mbrown009 9 5,755 Jun-20-2024, 07:59 PM
Last Post: AdamHensley
  Assigning conditional values in Pandas Scott 3 2,124 Dec-19-2023, 03:10 AM
Last Post: Larz60+
  HTML Decoder pandas dataframe column mbrown009 3 2,569 Sep-29-2023, 05:56 PM
Last Post: deanhystad
  Increase df column values decimals SriRajesh 2 1,866 Nov-14-2022, 05:20 PM
Last Post: deanhystad
  pandas column percentile nuncio 7 4,432 Aug-10-2022, 04:41 AM
Last Post: nuncio
  pandas: Compute the % of the unique values in a column JaneTan 1 2,394 Oct-25-2021, 07:55 PM
Last Post: jefsummers
  update values in one dataframe based on another dataframe - Pandas iliasb 2 12,903 Aug-14-2021, 12:38 PM
Last Post: jefsummers
  Pandas Data frame column condition check based on length of the value aditi06 1 3,679 Jul-28-2021, 11:08 AM
Last Post: jefsummers

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020