Showing posts with label pandas. Show all posts
Showing posts with label pandas. Show all posts

Thursday, April 11, 2019

pandas : drop rows with null only from specific columns

 aka : drop rows for certain columns if null

Tough one to find - and of course, as usual, DuckDuckGone is totally useless..

Thank you Google : 

df.dropna( axis=0, subset=column_list )

Saturday, January 19, 2019

My Definition of Genius

Go Stuart!

https://www.kryogenix.org/code/browser/sorttable/

Can you do better though? Yes, the user must know that he can sort. What's the best way to say that? Here's my take :

If,
       the user has not exercised this function upon loading this page,
then,
     anytime
    the header fields come into view, give them a halo that fades (how cool would that be!)

In addition, the background color should change upon mouseover.

Go for it Stu!

This one seems to have hints on how to accomplish the response to mouseover : https://www.w3schools.com/howto/howto_js_sort_table.asp

Tuesday, April 17, 2018

Pandas and XlsxWriter

Can you add an Excel table using a pandas dataframe to an existing worksheet?

No. What you can do is use pandas.dataframe.to_excel to create the sheet with the dataframe inserted to start from a certain row, and then you can use

pandas.ExcelWriter to capture the book and sheet and then use

sheet.write to insert values..

Sunday, March 04, 2018

Python : Pretty Print a Table

That is, if you've set up a board
[ ['O', 'O', 'O', 'O', 'O'], ['O', 'O', 'O', 'O', 'O'], ['O', 'O', 'O', 'O', 'O'], ['O', 'O', 'O', 'O', 'O'], ['O', 'O', 'O', 'O', 'O'] ]

How do you get

O O O O O
..
O O O O O

You get the idea..

def print_board(board_in ) :
  for row in board_in :
    print " ".join(row)

Is one way out..

Per https://stackoverflow.com/questions/13214809/pretty-print-2d-python-list

these may also be of help :

from prettytable import PrettyTable

x = [["A", "B"], ["C", "D"]]

p = PrettyTable()
for row in x:
    p.add_row(row)

print p.get_string(header=False, border=False)

from pandas import *
x = [["A", "B"], ["C", "D"]]
print DataFrame(x)

   0  1
0  A  B
1  C  D
Python pretty print a dict :

pprint.pprint( dict ) will give you :
>>> pprint.pprint( transition_counts )
{('NN', 'NN'): 16241,
 ('NN', 'RB'): 2431,
 ('NN', 'TO'): 5256,
 ('RB', 'NN'): 358,
 ('RB', 'RB'): 2263,
 ('RB', 'TO'): 855,
 ('TO', 'NN'): 734,
 ('TO', 'RB'): 200,
 ('TO', 'TO'): 2}