Home > front end >  Removing datatype information line from python head function
Removing datatype information line from python head function

Time:10-21

I want to access the top 6 items in a pandas dataframe. I am doing this by using .head(n=6). This works fine and will show me the first 6 values. my problem is that it also shows the type of data that the data is. In this case I have my 6 values and at the bottom of my values I see : Name: Column 7, dtype: int64.

When I do:

Print(df_column_7.head(n=6)

I get 6 values and an additional datatype line.

I am struggling to find a way to remove the this additional data type information provided by .head(). I want to get rid of this data type information as I will be adding the .head(n=6) into a Django model. And the datatype info will mess up the model entry.

CodePudding user response:

Since your use head on pandas series, you'll get this line by default.

>>> d = pd.Series(list('abcdefg'), name='col_1').to_frame() 

>>> d.col_1.head(n=3)
0    a
1    b
2    c
Name: col_1, dtype: object

If you need to omit last line, you can do:

>>> print(d.col_1.head(n=3).to_string())
0    a
1    b
2    c

CodePudding user response:

I could not see the problem with a dataframe I have tested. So I could not try, but try and let me know if this helps:

display(df_column_7.head(6))
  • Related