Reputation: 409
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
Reputation: 605
I think following code will solve your purpose
sensex_close = pd.read_csv('sensex.csv',index_col="Date")[["Close"]]
Upvotes: 2
Reputation: 4864
sensex=pd.read_csv("sensex.csv",index_col="Date", usecols=["Close"])
Upvotes: 0