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.
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.
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.
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.
To read CSV file without header, use the header parameter and set it to “None” in the read_csv() method.
print ibm["Close"].to_string(header=False)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With