I'm having an issue with reading an excel file into a Python program:
This my read:
data = pd.read_excel('<file path>PriceOdometerV3.xlsx')
This is what I'm trying to read it into:
df_X = data[:, np.newaxis,2]
And this is the message I'm getting:
TypeError: '(slice(None, None, None), None, 2)' is an invalid key
Suggestions? I'm know I'm missing a parameter that'll dice up the file, but what?
I tried out your code and for some reason could not get it to like using pandas for reading in the Excel spreadsheet. I have had better luck using the "openpyxl" package. If you have that package you might review the following sample program I built.
from openpyxl import load_workbook
import pandas as pd
data = load_workbook(filename = 'PriceOdometerV3.xlsx')
sheet_names = data.sheetnames
name = sheet_names[0]
sheet_ranges = data[name]
df_x = pd.DataFrame(sheet_ranges.values)
print(df_x)
Here was some sample output from a small spreadsheet that had two columns in it, Odometer Reading and Price.
==>python3 Excel.py
0 1
0 Odometer Reading Price
1 107338 10000
2 85000 14000
3 205777 5535
Perhaps that is an alternative you could use. Hope that helps.
Regards.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.