0

I am trying to import data from an excel file. I would like to import from a specific sheet and in that specific sheet only import certain columns. The code I am using is as follows:

%matplotlib inline

import pandas as pd
import math
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

sns.set(style="darkgrid")

# Input Portfolio data

xl_file=pd.ExcelFile('C:/Users/e877780/Desktop/DEV/S2_SK_S_06_02_input.xlsx')
s2_0602=xl_file.parse("S.06.02")[('C0080','C0090')]

My idea is to only import columns C0080 and C0090. I I just use one, it works but also does not keep the column name. Can someone help Thks

2
  • Use pandas read_excel. You can specify the sheetname and columns to use. Commented Mar 28, 2019 at 15:45
  • 1
    Specifically this answer from the duplicate. Commented Mar 28, 2019 at 15:47

1 Answer 1

0

You can try this:

xl_file=pd.ExcelFile('C:/Users/e877780/Desktop/DEV/S2_SK_S_06_02_input.xlsx')
sheet1=xl_file.parse("S.06.02")
s2_0602 = sheet1[['C0080','C0090']]

Hope it help

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. It works fine

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.