Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
106 views
in Technique[技术] by (71.8m points)

Python Code works in Atom but not in Spyder

I'm in a Python class right now and I was looking at switch from Atom and move to Spyder. My script imports and excel file, throws out 2 columns that I don't care about. I then rename the columns and try to output the results of one column. When I ran the code below in Atom, it worked fine. In Spyder, I get a traceback error.

import numpy as np
import pandas as pd

# Import the excel file I need. Also ignore certain rows I don't care about
energy = pd.read_excel('Energy Indicators.xls', skiprows=17, skipfooter=38)

# setup the new column names
nms = ['Country', 'Energy Supply', 'Energy Supply per Capita', '% Renewable']

# drop the columns I don't care about and rename the columns to what I want
energy = energy.drop(['Unnamed: 0', 'Unnamed: 1'], axis=1)
energy.columns = [nms]

# print out the column labeled 'Country'
print(energy['Country'])

In the Atom terminal, the script outputs a single column of the 'Country' Label (Which is what I want). In Spyder I get:

TypeError: only integer scalar arrays can be converted to a scalar index click here for error pic

question from:https://stackoverflow.com/questions/65941727/python-code-works-in-atom-but-not-in-spyder

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...