Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
298 views
in Technique[技术] by (71.8m points)

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:

enter image description here

this is the output format i get from the code:

enter image description here

question from:https://stackoverflow.com/questions/65859714/how-to-print-multiple-columns-as-a-data-frame-python

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...