亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么沒有定義 csv?

為什么沒有定義 csv?

呼喚遠方 2022-09-20 17:27:01
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'>
查看完整描述

1 回答

?
BIG陽

TA貢獻1859條經驗 獲得超6個贊

您粘貼了錯誤的代碼。在回溯中,斷層線為 3,但在此代碼中為 5 - 缺少的兩行可能是“導入 csv”行。


查看完整回答
反對 回復 2022-09-20
  • 1 回答
  • 0 關注
  • 131 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號