问题陈述
如何使用熊猫读取csv文件,而熊猫的csv文件在块之间有重叠?
例如,假设列表indexes表示我希望阅读的某些数据的索引。
indexes = [0,1,2,3,4,5,6,7,8,9]
Read_csv(文件名,chunksize=None):
indexes = [0,1,2,3,4,5,6,7,8,9] # read in all indexes at once
Read_csv(文件名,chunksize=5):
indexes = [[0,1,2,3,4], [5,6,7,8,9]] # iteratively read in mutually exclusive i
我正在尝试将一个大的CSV文件拆分为两个文件。我正在使用下面的代码 import pandas as pd
#csv file name to be read in
in_csv = 'Master_file.csv'
#get the number of lines of the csv file to be read
number_lines = sum(1 for row in (open(in_csv)))
#size of rows of data to write to the csv,
#you can change the row size accor
我使用文本文件,其中包含前6行中的一些基本信息,包括空行。我必须将数据导入、处理并导出到另一个csv。下面是前6行的示例:
Foov7.9 - bar.raw created at 10:45:25 on 10.02.2015:
(empty row)
(empty row)
A B C D
a b c d
(empty row)
在熊猫中,我使用第4行:
A B C D
作为dataframe的标题:
data1 = pd.read_table(dataset1,header = 1, skiprows = (4,5), index_col=None, delimiter=r"\t&
我正在测试使用熊猫和Python多处理模块同时读取一个大型CSV文件的可能性。
有一些节省时间,但它们是相当少的。起初,我认为这可能与从硬盘读取数据的速度有关,但我不认为这是为什么,因为读取大型文本文件或大型Python泡菜文件要快得多。
请参阅下面的代码:
import pandas as pd
import numpy as np
import time
from datetime import datetime
import multiprocessing as mp
from util import memchk
import re
FILE_LENGTH = 1000000
IN
我试图在一个目录中读取多个csv文件,使用熊猫。我用了两种方法,两种方法都没用。
import os
from glob import glob
from math import*
from numpy import*
from pandas import*
path = '/Volumes/File/Names/Stuff 2016'
for filename in glob(os.path.join(path, '*.csv')):
qu = read_csv(filename, delimiter = ';', header
我编写了一个小的简单脚本来读取和处理一个巨大的CSV文件(~150 do ),它每个循环读取5e6行,将其转换为Pandas DataFrame,使用它执行一些操作,然后继续读取接下来的5e6行。
尽管它完成了这项工作,但在每次迭代时,都需要更长的时间才能找到要读取的下一个行块,因为它必须跳过更多的行。我阅读了许多关于块的使用(作为读取器迭代器)的答案,尽管一旦读取了块,我就需要连接这些块来创建一个DataFrame (与截短的行和东西有关的各种问题),所以我不喜欢走这条路。
是否可以使用某种游标来提醒read_csv函数从它停止的位置开始读取?
代码的主要部分如下所示:
while cond
我有一个带有utf-16 in编码的csv文件,我尝试在云函数中打开它
import pandas as pd
from io import StringIO as sio
with open("gs://bucket_name/my_file.csv", "r", encoding="utf16") as f:
read_all_once = f.read()
read_all_once = read_all_once.replace('"', "")
file_like = s
我有一个很大的数据帧(大约500万行),其中包含一些错误的数据。我已经识别了具有错误数据的行的索引,现在我正在尝试从数据帧中删除“错误”的行。 由于数据帧的大小,我在读取csv时使用了chunksize功能。为了跳过“错误”的行,我使用了skiprows和error_bad_lines features。我还使用low_memory特性来防止警告(出于示例的目的,我只读取了前20000行)。然后,我将新数据帧保存在新的csv中。 问题是,只有前9个“错误”行被跳过,然后“错误行”仍然被读取(并保存到输出csv)。 下面是我的代码: for df in pd.read_csv('dat
我希望将一个目标目录中的多个CSV文件(列数不同)读入单个Python,以有效地搜索和提取数据。
示例文件:
Events
1,0.32,0.20,0.67
2,0.94,0.19,0.14,0.21,0.94
3,0.32,0.20,0.64,0.32
4,0.87,0.13,0.61,0.54,0.25,0.43
5,0.62,0.21,0.77,0.44,0.16
以下是我到目前为止所拥有的:
# get a list of all csv files in target directory
my_dir = "C:\\Data\\"
filelist = []
os
我在读取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 dict
我正在尝试用Python创建一些图表。我在CSV文件中有这个数据集:
Banana Water Rice
Rice Water
Bread Banana Juice
我有这样的代码:
import numpy as np
from pandas import DataFrame
import matplotlib
matplotlib.use('agg') # Write figure to disk instead of displaying (for Windows Subsystem for Linux)
import matplotlib.