Last active
February 12, 2022 19:26
-
-
Save jj-github-jj/6a49ab6ce96371d21ede4d924f9a7001 to your computer and use it in GitHub Desktop.
my dataframe snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create an 8 row by 2 columns dataframe with column labels | |
df=pd.DataFrame(np.reshape(np.zeros(16),(8,2)),columns=['x','y']) # create an 8 row by 2 columns df | |
c=df23.columns.to_list() | |
c[0] | |
df.iloc[0:,0:2] # rows 0 through end of column 0 and 1 | |
#---------- | |
df.drop(df.columns[[0, 4, 2]], axis = 1, inplace = True) #drop columns using column index | |
#---------- | |
from IPython.display import display, HTML | |
def pretty_print(df): | |
return display( HTML( df.to_html().replace("\\n","<br>") ) ) | |
# display long column names vertical orientation | |
def format_vertical_headers(df): | |
"""Display a dataframe with vertical column headers""" | |
styles = [dict(selector="th", props=[('width', '40px')]), | |
dict(selector="th.col_heading", | |
props=[("writing-mode", "vertical-rl"), | |
('transform', 'rotateZ(180deg)'), | |
('height', '290px'), | |
('vertical-align', 'top')])] | |
return (df.fillna('').style.set_table_styles(styles)) | |
format_vertical_headers(df2.iloc[0:2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment