Python Forum

Full Version: display the result of Dataframe in tabulate format
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I concated two Dataframes (df1,df2) then return the max values in each cluster,

dff=pd.concat([df1,df2]).drop_duplicates(['cluster','accuercy '],keep='last').sort_values('cluster')

dfs22=dff.groupby(['cluster'], sort=False)['accuercy'].max()
the Dataframe (dff) look like this

+----+-----------+----------+------------+
|cluster | device | accuercy
|----+-----------+----------+------------|
| 0 | 0 | 0.80 |
| 1 | 1 | 0.85 |
| 1 | 2 | 0.81 |
| 1 | 3 | 0.83 |
| 2 | 4 | 0.84 |
| 2 | 5 | 0.83 |
| 0 | 6 | 0.84 |
| 0 | 7 | 0.83 |
| 0 | 8 | 0.81 |
| 0 | 9 | 0.85 |
+----+-----------+----------+------------+
How can I display the result of a dfs22 in tabulate?

+----+-----------+----------+------------+
|cluster | device | accuercy
|----+-----------+----------+---- -------|
| 1 | 1 | 0.85 |
| 2 | 4 | 0.84 |
| 0 | 9 | 0.85 |
+----+-----------+----------+--------- --+
I tried using the following code

print(tabulate(dfs2, headers='keys', tablefmt='psql'))
but idosent work !!!!