相关疑难解决方法(0)

Python中的Pandas和NumPy + SciPy有什么区别?

它们看起来非常相似,我很好奇哪种方案对财务数据分析更有利.

python numpy scipy pandas

187
推荐指数
2
解决办法
12万
查看次数

如何将多维数组写入文本文件?

在另一个问题中,如果我可以提供我遇到问题的阵列,其他用户会提供一些帮助.但是,我甚至在基本的I/O任务中失败,例如将数组写入文件.

任何人都可以解释我需要将4x11x14 numpy数组写入文件需要什么样的循环?

这个数组包含四个11 x 14数组,所以我应该用一个漂亮的换行符来格式化它,以便在其他数据上更容易读取文件.

编辑:所以我尝试了numpy.savetxt函数.奇怪的是,它给出了以下错误:

TypeError: float argument required, not numpy.ndarray
Run Code Online (Sandbox Code Playgroud)

我假设这是因为该函数不适用于多维数组?我想在一个文件中找到任何解决方案吗?

python file-io numpy

103
推荐指数
6
解决办法
24万
查看次数

如何使用Python读写CSV文件?

我有一个example.csv包含内容的文件

1,"A towel,",1.0
42," it says, ",2.0
1337,is about the most ,-1
0,massively useful thing ,123
-2,an interstellar hitchhiker can have.,3
Run Code Online (Sandbox Code Playgroud)

我如何example.csv用Python 阅读?

同样,如果我有

data = [(1, "A towel,", 1.0),
        (42, " it says, ", 2.0),
        (1337, "is about the most ", -1),
        (0, "massively useful thing ", 123),
        (-2, "an interstellar hitchhiker can have.", 3)]
Run Code Online (Sandbox Code Playgroud)

如何data使用Python 写入CSV文件?

python csv

33
推荐指数
1
解决办法
4万
查看次数

如何在python中将csv文件导入为numpy.array?

说我有这种格式的csv file.csv:

dfaefew,432,1
vzcxvvz,300,1
ewrwefd,432,0
Run Code Online (Sandbox Code Playgroud)

如何将第二列作为numpy.array导入,将第三列作为另一个列导入如下:

second = np.array([432, 300, 432])
third = np.array([1, 1, 0])
Run Code Online (Sandbox Code Playgroud)

我在Ubuntu中使用python2.7.

先生!

python csv numpy

25
推荐指数
2
解决办法
9万
查看次数

如何将不同类型的数据从文件导入Python Numpy数组?

说我有一个文件myfile.txt包含:

1   2.0000  buckle_my_shoe
3   4.0000  margery_door
Run Code Online (Sandbox Code Playgroud)

如何将数据从文件导入numpy数组作为int,float和string?

我的目标是:

array([[1,2.0000,"buckle_my_shoe"],
[3,4.0000,"margery_door"]])
Run Code Online (Sandbox Code Playgroud)

我一直玩弄以下无济于事:

a = numpy.loadtxt('myfile.txt',dtype=(numpy.int_,numpy.float_,numpy.string_))
Run Code Online (Sandbox Code Playgroud)

编辑:另一种方法可能是使用ndarray类型并转换后.

b = numpy.loadtxt('myfile.txt',dtype=numpy.ndarray)

    array([['1', '2.0000', 'buckle_my_shoe'],
       ['3', '4.0000', 'margery_door']], dtype=object)
Run Code Online (Sandbox Code Playgroud)

python numpy

11
推荐指数
2
解决办法
1万
查看次数

在Python中读取scipy/numpy中的csv文件

我在python中读取由制表符分隔的csv文件时遇到问题.我使用以下功能:

def csv2array(filename, skiprows=0, delimiter='\t', raw_header=False, missing=None, with_header=True):
    """
    Parse a file name into an array. Return the array and additional header lines. By default,
    parse the header lines into dictionaries, assuming the parameters are numeric,
    using 'parse_header'.
    """
    f = open(filename, 'r')
    skipped_rows = []
    for n in range(skiprows):
        header_line = f.readline().strip()
        if raw_header:
            skipped_rows.append(header_line)
        else:
            skipped_rows.append(parse_header(header_line))
    f.close()
    if missing:
        data = genfromtxt(filename, dtype=None, names=with_header,
                          deletechars='', skiprows=skiprows, missing=missing)
    else:
    if delimiter != '\t':
        data = genfromtxt(filename, dtype=None, names=with_header, delimiter=delimiter, …
Run Code Online (Sandbox Code Playgroud)

python csv numpy matplotlib scipy

3
推荐指数
1
解决办法
2万
查看次数

CSV到python中的图像

我想用 csv 数据创建一个图像。

我正在阅读 csv:

f = open('file.csv', 'rb')
reader = csv.reader(f)
Run Code Online (Sandbox Code Playgroud)

从这里开始,我想制作一个灰度图像,将列表中的每一行数字转换为图像文件中的一行强度。

不确定什么会有用,但这里有一些关于我的 csv 文件的详细信息:使用浮点数,列:315,行:144

谢谢

python csv image

2
推荐指数
1
解决办法
2万
查看次数

如何将数据从Excel导入python数组?

我有一个非常基本的神经网络。对于数组数据,我需要执行什么代码才能将数组指向Excel文件中的数据?

这是带有硬编码数据的代码。

我如何告诉阵列查看计算机上的另一个文件?

import numpy as np

# X = (hours studying, hours sleeping), y = score on test
xAll = np.array(([2, 9], [1, 5], [3, 6], [5, 10], [8,8], [1,4]), 
dtype=float) # input data
y = np.array(([92], [60], [89], [91], [99]), dtype=float) # output

# scale units
xAll = xAll/np.amax(xAll, axis=0) # scaling input data
y = y/100 # scaling output data (max test score is 100)

# split data
X = np.split(xAll, [5])[0] # training data has to …
Run Code Online (Sandbox Code Playgroud)

python numpy neural-network

2
推荐指数
1
解决办法
93
查看次数

Python:如何在numpy数组中逐行读取?

我想知道我们可以在一个数组中逐行读取.例如:

array([[ 0.28,  0.22,  0.23,  0.27],
       [ 0.12,  0.29,  0.34,  0.21],
       [ 0.44,  0.56,  0.51,  0.65]])
Run Code Online (Sandbox Code Playgroud)

以数组形式读取第一行以执行某些操作,然后继续第二行数组:

array([0.28,0.22,0.23,0.27])
Run Code Online (Sandbox Code Playgroud)

产生上述数组的原因是这两行代码:

from numpy import genfromtxt
single=genfromtxt('single.csv',delimiter=',')
Run Code Online (Sandbox Code Playgroud)

single.csv

0.28,  0.22,  0.23,  0.27
0.12,  0.29,  0.34,  0.21
0.44,  0.56,  0.51,  0.65
Run Code Online (Sandbox Code Playgroud)

使用readlines()看起来像生成列表而不是数组.就我而言,我正在使用csv文件.我试图逐行使用值行而不是一起使用它们以避免内存错误.谁能帮我?

with open('single.csv') as single:
    single=single.readlines()
Run Code Online (Sandbox Code Playgroud)

python arrays numpy

-4
推荐指数
2
解决办法
2万
查看次数

标签 统计

python ×9

numpy ×7

csv ×4

scipy ×2

arrays ×1

file-io ×1

image ×1

matplotlib ×1

neural-network ×1

pandas ×1