Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在python中将数组值导出到csv文件中的列_Python_Export To Csv - Fatal编程技术网

在python中将数组值导出到csv文件中的列

在python中将数组值导出到csv文件中的列,python,export-to-csv,Python,Export To Csv,我有这个变量,它是一列16250个条目,如图所示 output_values array([0, 0, 0, ..., 0, 0, 0]) output_values.shape and it is an array of (16250,) 我想将这些值写入csv文件的第14列,其中包含路径 filename = 'C:/Users/tmp/Desktop/test/input_file_data.csv' 这可能吗?您必须将文件中的内容读入pandas,并在该列后面附加以下内容: im

我有这个变量,它是一列16250个条目,如图所示

output_values
array([0, 0, 0, ..., 0, 0, 0])

output_values.shape
 and it is an array of (16250,)
我想将这些值写入csv文件的第14列,其中包含路径

filename = 'C:/Users/tmp/Desktop/test/input_file_data.csv'

这可能吗?

您必须将文件中的内容读入pandas,并在该列后面附加以下内容:

import pandas as pd
import numpy as np

df = pd.read_csv('C:/Users/tmp/Desktop/test/input_file_data.csv')
df = df.assign(new_col=output_values)
df.to_csv('C:/Users/tmp/Desktop/test/input_file_data_appended.csv')

new\u col
将是熊猫数据框对象
df
中新列的名称。这也可以用numpy genfromtxt完成,但它需要更多的代码。

您能给出几行csv文件吗?