Reputation: 1293
I have a dataframe and need to print the output of some aggregations and such.
For example, a line in my script has:
pd.f_type = inventory['fruit'].value_counts()
print(f_type)
And its output like this:
apple 2
watermelon 1
pineapple 1
grapefruit 1
orange 1
Name: fruit, dtype: int64
How I can I remove the last line with "Name..."? I don't need it. I just need to see the actual output. Do I need to print with a for loop or something?
Upvotes: 5
Views: 4407
Reputation: 2026
in your case you can also do:
print(pd.DataFrame(f_type))
The name and dtype underneath the data is printed out only for pandas.Series
Upvotes: 3
Reputation: 3318
If the removal of the last line is just for the sake of output, you can do like this:
f_type.to_string()
However, be careful with using .to_string()
on large dataframes, because it will convert and print the entire dataframe, not just the amount of rows specified in pd.options.display.max_rows
.
In addition to that, if you have a lot of columns the output will be pretty messed up. In that case you should probably do a print loop instead.
Upvotes: 8