0

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

4
  • 1
    provide the df1 and df dataframe values also Commented Jan 23, 2021 at 13:40
  • Your code works fine and returns the dataframe. Check the type of df1 by using print(type(df1)) Commented Jan 23, 2021 at 13:48
  • ok, I checked the type and its a data frame. but the output appearance is different from when I print the df in another cell Commented Jan 23, 2021 at 14:38
  • 1
    You can use display() instead of print() for the required output. Commented Jan 23, 2021 at 15:31

1 Answer 1

1

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.