简体   繁体   中英

how to print multiple columns as a data frame - python

I need to print 2 specific columns as a data frame and not a series.

this question is different from when df1 is printed it returns a series. movie title and movie year are the columns I need to print. I used the df = my_series.to_frame() function but it still returns a series.

def find_movie_by_year():
    x = input("enter movie year")
    d = df[df["title_year"] == int(x)]
    df1 = d[["movie_title","title_year"]]
    print('''

    ''')
    print(df1)

EDIT 1:

this is the output format i need:

在此处输入图像描述

this is the output format i get from the code:

在此处输入图像描述

You can use display function instead of simply printing it.

def find_movie_by_year():
x = input("enter movie year")
d = df[df["title_year"] == int(x)]
df1 = d[["movie_title","title_year"]]
print('''

''')
#print(df1)
display(df1)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM