plt.style.use('ggplot')g = sns.catplot( x = 'YearBuilt', y = 'SalePrice', data = train, kind='swarm', hue='OverallQual', palette = 'Set2', height=6, aspect=2)locs, labels = plt.xticks() # use if needed, as explained below.for axes in g.axes.flat: for ind, label in enumerate(axes.get_xticklabels()): if ind % 8 == 0: # every nth label is kept label.set_visible(True) else: label.set_visible(False)plt.title('House Sale Prices (log scale) vs. Year Built and Overall Quality')plt.xlabel('Year Built')plt.yscale('log')plt.ylim([4e4, 6e5])plt.yticks([6e4, 1e5, 1.4e5, 1.8e5, 2.4e5, 3.2e5, 4e5, 6e5], ['60k', '100k', '140K', '180k', '240K', '320k', '600k'])plt.ylabel('Sale Price ($)')plt.show()我正在尝试对csv文件进行相对简单的解析,我不明白为什么csv模块不起作用。这是我的代码:import csvdef getFromCSV(fileName): with open(fileName, 'r') as f: reader = csv.reader(f) data = list(reader) return datadef append_row(fileName, my_list): with open(fileName, 'a') as output: writer = csv.writer(output) writer.writerow(my_list)data = getFromCSV('dh_internal_all.csv')for row in data: if '25252' not in row: print(row) append_row('parsed.csv',[row])这将返回:dh-dfbhv2l:Documents jwr38$ python3 remove_bad_data.py Traceback (most recent call last): File "remove_bad_data.py", line 13, in <module> data = getFromCSV('dh_internal_all.csv') File "remove_bad_data.py", line 3, in getFromCSV reader = csv.reader(f)NameError: name 'csv' is not defined提前感谢您的任何提示。编辑:当我在终端中运行时,然后,然后,它似乎识别它,它返回:python3import csvcsv<module 'csv' from '/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/csv.py'>
添加回答
举报
0/150
提交
取消