SHARE
TWEET

pandas sort columns separatelly

furas Jul 25th, 2018 (edited) 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import pandas as pd
  2.  
  3. summary = pd.DataFrame({
  4.     'two': pd.np.random.randint(0, 300, size=100),
  5.     'three': pd.np.random.randint(300, 600, size=100),
  6.     'four': pd.np.random.randint(600, 900, size=100),
  7. })
  8.  
  9. print(df.head())
  10.  
  11. top10 = pd.DataFrame()  # new dataframe for results
  12.  
  13. for name in summary.columns:
  14.     column = summary[name].sort_values(ascending=False).head(10)
  15.     column = column.reset_index(drop=True)
  16.     top10[name] = column
  17.  
  18.     #top10[name] = summary[name].sort_values(ascending=False).head(10).reset_index(drop=True)
  19.  
  20. print(top10.head())
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top