[英]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.我需要将 2 个特定列打印为数据框而不是系列。
this question is different from when df1 is printed it returns a series.这个问题与打印 df1 时不同,它返回一个系列。 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.
我使用了 df = my_series.to_frame() function 但它仍然返回一个系列。
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:编辑1:
this is the output format i need:这是我需要的 output 格式:
this is the output format i get from the code:这是我从代码中得到的 output 格式:
You can use display function instead of simply printing it.您可以使用显示function 而不是简单地打印它。
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.