Eip_Nit_AC 2023-03-23 15:25 采纳率: 25%
浏览 15
已结题

关于#pandas#的问题,如何解决?

使用pandas引用CSV文件报错


PS C:\Users\Eip_N\Downloads\k_means-master> & D:/Python37/python.exe c:/Users/Eip_N/Downloads/k_means-master/k_means-master/src/run.py
Traceback (most recent call last):
  File "c:/Users/Eip_N/Downloads/k_means-master/k_means-master/src/run.py", line 37, in <module>
    main(input_fn, output_fn, args.clusters)
  File "c:/Users/Eip_N/Downloads/k_means-master/k_means-master/src/run.py", line 13, in main
    df = pd.read_csv(dataset_fn)
  File "D:\Python37\lib\site-packages\pandas\io\parsers.py", line 688, in read_csv
    return _read(filepath_or_buffer, kwds)
  File "D:\Python37\lib\site-packages\pandas\io\parsers.py", line 454, in _read
    parser = TextFileReader(fp_or_buf, **kwds)
  File "D:\Python37\lib\site-packages\pandas\io\parsers.py", line 948, in __init__
    self._make_engine(self.engine)
  File "D:\Python37\lib\site-packages\pandas\io\parsers.py", line 1180, in _make_engine
    self._engine = CParserWrapper(self.f, **self.options)
  File "D:\Python37\lib\site-packages\pandas\io\parsers.py", line 2010, in __init__
    self._reader = parsers.TextReader(src, **kwds)
  File "pandas\_libs\parsers.pyx", line 382, in pandas._libs.parsers.TextReader.__cinit__
  File "pandas\_libs\parsers.pyx", line 674, in pandas._libs.parsers.TextReader._setup_parser_source
FileNotFoundError: [Errno 2] No such file or directory: 'data\\NYC_Free_Public_WiFi_03292017.csv'

源代码:

import os
import argparse
import pandas as pd
import sys, os
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from src.clustering import KMeans
from src.point import Point

def main(dataset_fn, output_fn, clusters_no):
    geo_locs = []
    # read location data from csv file and store each location as a Point(latit,longit) object
    df = pd.read_csv(dataset_fn)
    for index, row in df.iterrows():
        loc_ = Point(float(row['LAT']), float(row['LON']))  #tuples for location
        geo_locs.append(loc_)
    # run k_means clustering
    model = KMeans(geo_locs, clusters_no)
    flag = model.fit(True)
    if flag == -1:
        print("No of points are less than cluster number!")
    else:
        # save clustering results is a list of lists where each list represents one cluster
        model.save(output_fn)

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="Run k-means for location data",
                                     formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('--input', type=str, default='NYC_Free_Public_WiFi_03292017.csv',
                        dest='input', help='input location file name')
    parser.add_argument('--output', type=str, default='output.csv', dest='output', 
                        help='clusters output file name')
    parser.add_argument('--clusters', type=int, default=8, dest='clusters', help='number of clusters')
    args = parser.parse_args()
    input_fn = os.path.join("data", args.input)
    output_fn = args.output
    main(input_fn, output_fn, args.clusters)


img

  • 写回答

2条回答 默认 最新

  • threenewbee 2023-03-23 15:32
    关注
    'data\\NYC_Free_Public_WiFi_03292017.csv'
    目测data后面多了 \
    
    
    评论 编辑记录

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 4月10日
  • 修改了问题 3月23日
  • 创建了问题 3月23日

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度