Bottom Page

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
Quote
#2
D = pd.read_csv('sort.csv')
E = pd.DataFrame(D)
print(E[E['A'] < 0])
print(E[E['A'] > 0])
Quote
#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 

Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Pandas DataFrame and unmatched column sritsv19 0 158 Jul-07-2020, 12:52 PM
Last Post: sritsv19
  Assigning Column nunique values to another DataFrame column Pythonito 0 137 Jun-25-2020, 05:04 PM
Last Post: Pythonito
  Pandas + Groupby + Filter unique values JosepMaria 1 145 Jun-15-2020, 08:15 AM
Last Post: JosepMaria
  Pandas - Dynamic column aggregation based on another column theroadbacktonature 0 213 Apr-17-2020, 04:54 PM
Last Post: theroadbacktonature
  Add column to CSV using Pandas nsadams87xx 2 344 Apr-15-2020, 08:41 PM
Last Post: snippsat
  Counter to keep track how many times values in a list appear in each row in a column chief 0 190 Mar-24-2020, 08:14 PM
Last Post: chief
  add formatted column to pandas data frame alkaline3 0 232 Mar-22-2020, 06:44 PM
Last Post: alkaline3
  Pandas copying wrong values vmarg 2 286 Jan-06-2020, 09:45 AM
Last Post: vmarg
  itertuples, new column, datetime, pandas karlito 6 671 Nov-29-2019, 11:07 AM
Last Post: karlito
  Dropping a column from pandas dataframe marco_ita 6 4,721 Sep-07-2019, 08:36 AM
Last Post: marco_ita

Forum Jump:


Users browsing this thread: 1 Guest(s)