Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove Header and Footer from Pandas Dataframe print

The following code prints all the values I want but has "Date" as the first row and "Name: Close, Length: 1828, dtype: float64" as the last row

import pandas as pd
from pandas.io.data import DataReader
from datetime import datetime

ibm = DataReader('IBM',  'yahoo', datetime(2009,1,1))
pd.set_option('display.max_rows',len(ibm))
print ibm["Close"]

How do I print the data w/o this first "Date" line and the last "Name: Close, Length: 1828, dtype:float64" line? Slicing doesn't work, I've tried print ibm["Close"][1:-1] and it just cuts off the 2nd and 2nd to last row.

like image 870
Dante Avatar asked Apr 08 '16 01:04

Dante


People also ask

How do I remove a header from a DataFrame in Python?

How do I remove a header from a Dataframe in Python? Just simply put header=False and for eliminating the index using index=False. If you want to learn more about Pandas then visit this Python Course designed by industrial experts.

How do I skip a header in a data frame?

Example: Skip Header when Reading CSV File as pandas DataFrame. In this example, I'll explain how to remove the header when importing a CSV file as a pandas DataFrame. For this task, we can apply the read_csv function as shown below. Within the read_csv function, we have to set the skiprows argument to be equal to 1.

How do I remove a label from a data frame?

DataFrame - drop() function The drop() function is used to drop specified labels from rows or columns. Remove rows or columns by specifying label names and corresponding axis, or by specifying directly index or column names. When using a multi-index, labels on different levels can be removed by specifying the level.

How can I read Pandas without header?

To read CSV file without header, use the header parameter and set it to “None” in the read_csv() method.


1 Answers

print ibm["Close"].to_string(header=False)
like image 103
Colin Avatar answered Sep 30 '22 15:09

Colin