我是OSX的新手。已安装自制的Python 3.7.4,并尝试在VS Code中使用它。我很确定我的代码是正确的-它在Windows上,在OSX上的iPython或文件(即python file.py)上都可以正常运行。
但是,当我尝试使用VS Code的“在Python终端中运行选择/文件”功能时,输出结果完全是一团糟,到处都是重复的代码和错误(主要是IndentationError)。
也许有人以前看过这个问题?请帮忙!
import numpy as np
import pandas as pd
from os import chdir, listdir
from os.path import dirname, realpath
try:
path = dirname(realpath(__file__))
except NameError:
path = '/Users/user/Desktop/project'
chdir(path)
origDF = pd.DataFrame({'name': ['one', 'two', 'three'], 'date': ['june', 'july', 'august'], 'A_1': [1,2,3], 'L_1': [2,2,2],
'TA': [1,1,1], 'TL': [2,2,2]})
dataDF = origDF.copy()
def test_equality(dataframe, item1, item2, threshold):
tmpDF = dataframe.copy()
tmpDF.loc[:, 'diff'] = abs(tmpDF[item1]/tmpDF[item2] - 1)
print('\nComparison of {i1} and {i2} with threshold {t}:\n'.format(
i1=item1, i2=item2, t=threshold))
print(tmpDF.loc[tmpDF['diff'] > threshold,
['name', 'date', item1, item2]])
# are totals equal?
for s in ['A', 'L']:
dataDF.loc[:, 'T{}_calc'.format(s)] = dataDF.loc[:, ['{}_'.format(s) in c and not any(
m in c for m in ['A_6', 'L_8']) for c in dataDF]].sum(axis=1, min_count=1)
test_equality(dataDF, 'TA_calc', 'TL_calc', 0.01)
# are totals equal to the stated totals?
for s in ['A', 'L']:
test_equality(dataDF, 'T{}'.format(s), 'T{}_calc'.format(s), 0.01)