0

This is my output in Pandas from CSV file.


Total Schools   Total Students  Total Budget    Average Math score  Average Reading score
     15             39,170      $24,649,428        78.99                81.88

d = {'Total Schools': [school_df['name'].count()], 'Total Students': [student_df['name'].count()], 'Total Budget':[school_df['budget'].sum()], 'Average Math score':[round(student_df['math_score'].mean(),2)], 'Average Reading score':[round(student_df['reading_score'].mean(),2)]}
school_summary = pd.DataFrame(d)
school_summary = school_summary.loc[:,['Total Schools','Total Students','Total Budget','Average Math score','Average Reading score']]
school_summary['Total Budget'] = school_summary['Total Budget'].map("${:,.0f}".format)
school_summary['Total Students'] = school_summary['Total Students'].map("{:,.0f}".format)

school_summary

Above is my code to create dataframe. I want to convert dataframe in to table formate. Would you please suggest me code. I know there is code school_summary.style.set_table_styles but I don't know how to use it?

Hetal
  • 21
  • 1
  • 4

1 Answers1

0

If you want to save to csv and look at it in excel or openoffice

if by table format you mean a csv. then just do

school_summary.to_csv(FILEPATH)

where FILEPATH is where you want to save your new csv file (like FILEPATH = r'C:\My Documents\myfile.csv' if you're using windows os)

If you want to pretty print in ipython

do from IPython.display import display then display(school_summary)

if you want to pretty print in Python console...

the best you can do is Pretty Printing a pandas dataframe

(Sorry to say, but a python console is not the best way to view data.)

Community
  • 1
  • 1
Kardo Paska
  • 504
  • 7
  • 17