【问题标题】:Cannot load cvs file in jupyter as well as in pycharm. How to load file?无法在 jupyter 和 pycharm 中加载 cvs 文件。如何加载文件?
【发布时间】:2021-03-28 07:35:50
【问题描述】:

import csv
import pandas as pd
from math import sqrt


def read_file(fileName):
    with open(fileName) as file:
        metadata = [next(file) for i in range(6)]
        title = metadata[0].split('=')[1]
        institution = metadata[1].split('=')[1]
        references = metadata[2].split('=')[1]
        comment = metadata[3].split('=')[1]
        trend = metadata[4].split('=')[1]
        cols = metadata[5].split(',')
        cols[4] = cols[4].rstrip()
        header = {
            'title': title,
            'institution': institution,
            'references': references,
            'comment': comment,
            'trend': trend
        }
        data = pd.read_csv(file, delimiter=',', dtype='float', names=cols)
        data['merge'] = data['TOPX/Poseidon'].combine_first(data['Jason-1']).combine_first(
            data['Jason-2']).combine_first(data['Jason-3'])
    return header, data

【问题讨论】:

  • 不要发布指向文本图像的链接。 将问题本身作为格式化文本发布

标签: python matplotlib


【解决方案1】:

file open 部分中将文件的完整路径作为参数传递

(r"C:\Path\to\your\file.csv)

或者您可能想使用 os.path 包将您的 csv 路径作为参数传递

os.path.realpath(__file__)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-09
    • 2017-05-17
    • 1970-01-01
    • 2021-11-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多