jeetkamal
jeetkamal

Reputation: 409

Reading only a single column from data frame

I have a dataframe. It has seven columns. I will take first column as index. I want to read only one column from that dataframe. I know if I want to read more than one, I can use usecols arguments. But for only single column, how I can read it? I can do it using the following two lines of code. But is it possible to read it with a single line of code?

sensex=pd.read_csv("sensex.csv",index_col="Date")
sensex_close=sensex.loc[:,["Close"]]

Upvotes: 2

Views: 426

Answers (2)

simar
simar

Reputation: 605

I think following code will solve your purpose

sensex_close = pd.read_csv('sensex.csv',index_col="Date")[["Close"]]

Upvotes: 2

Igor Rivin
Igor Rivin

Reputation: 4864

sensex=pd.read_csv("sensex.csv",index_col="Date", usecols=["Close"])

Upvotes: 0

Related Questions