current position:Home>PyPackage01---Pandas12_ print dataframe

PyPackage01---Pandas12_ print dataframe

2022-07-25 15:08:13Weigtang 406 team

  print dataframe Parameter control of ,index And column spacing . Look directly at the code ~

Remove index

import pandas as pd
pd.__version__
'1.1.5'
df = pd.DataFrame({
    "id":[1,2,3],"name":["jordan","kobe","duncan"],"team":["Bulls","Lakers","Spurs"]})
print(df)
   id    name    team
0   1  jordan   Bulls
1   2    kobe  Lakers
2   3  duncan   Spurs

Get rid of index

print(df.to_string(index=False))
 id    name    team
  1  jordan   Bulls
  2    kobe  Lakers
  3  duncan   Spurs

Set column spacing

print(df.to_string(index=False,col_space=10))
        id       name       team
         1     jordan      Bulls
         2       kobe     Lakers
         3     duncan      Spurs

                       2021-06-08 Jiulong lake, Jiangning District, Nanjing

copyright notice
author[Weigtang 406 team],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/206/202207251501086594.html

Random recommended