Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/308.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 2D数组转换为数据帧_Python_Pandas - Fatal编程技术网

将python 2D数组转换为数据帧

将python 2D数组转换为数据帧,python,pandas,Python,Pandas,我正在读取csv文件,其中每行根据第二个字段的值有不同的解释。每行多次表示相同的类型信息(在一行中多次重复不同的列值)。我需要逐行阅读,需要把它排列成不同的列表或2个数组 Like: with open('info.log','rt') as inputFile: filereader = csv.reader(inputFile, delimiter=',') for row in filereader: if (int(row[1]) == 5):

我正在读取csv文件,其中每行根据第二个字段的值有不同的解释。每行多次表示相同的类型信息(在一行中多次重复不同的列值)。我需要逐行阅读,需要把它排列成不同的列表或2个数组

Like:
with open('info.log','rt') as inputFile:
      filereader = csv.reader(inputFile, delimiter=',')
      for row in filereader:
          if (int(row[1]) == 5):
                for mylist in  (divide the long row into list of lists of fix N length) : # N will be number of columns here
                 array5.append(mylist[2:])   << Now this is an Array of  5 column.
                 # Or Can I append this list direct to dataframe A??

          elif (int(row[1]) == 4):
              for mylist in  (divide the long row into list of lists of fix M length):   # M will be number of columns here
                  array4.append(row[2:3]+mylist)
                  #Can I append this list direct to dataframe B??
比如:
打开('info.log','rt')作为输入文件:
filereader=csv.reader(inputFile,分隔符=',')
对于filereader中的行:
如果(int(行[1])==5):
对于中的mylist(将长行划分为固定长度的列表):#N将是此处的列数

array5.append(mylist[2:])为了改进您的问题并生成更有用的回答,我建议您的问题包含一些有代表性的数据。按照建议,添加了示例数据。您能显示您的预期输出吗?
DATA,5,time, <IP1, IP2, write, read,error>, <IP1, IP2, write, read,error>, <IP1, IP2, write, read,error>, <IP1, IP2, write, read,error>....
DATA,4,time, <port_index, read_users, write_users > <port_index, read_users, write_users> <port_index, read_users, write_users>...


DATA,5,20180529235221,::127.0.0.1,127.0.0.1,0,33345,36736,36751,0,::ffff:127.0.0.1,::ffff:127.0.0.1,0,33346,36736,74690,0,::ffff:127.0.0.1,::ffff:127.0.0.1,0,33347,36736,36749,0,
DATA,4,20180529235251,0,4263532,464027, 2,4181981,2060546,3,4181981,2060546, 4,4181981,2060546, 5,4181981,2060546, 6,4263221,464221, 7,418332,206023,8,4181232,2060232, 9,418123,206023, 10,41812323,202456
DATA,5,20180529235221,::127.0.0.1,127.0.0.1,0,33345,36736,36751,0,::ffff:127.0.0.1,::ffff:127.0.0.1,0,33346,36736,74690,0,::ffff:127.0.0.1,::ffff:127.0.0.1,0,33347,36736,36749,0
DATA,5,20180529235221,::127.0.0.1,127.0.0.1,0,33345,36736,36751,0,::ffff:127.0.0.1,::ffff:127.0.0.1,0,33346,36736,74690,0,::ffff:127.0.0.1,::ffff:127.0.0.1,0,33347,36736,36749,0,
DATA,5,20180529235221,::127.0.0.1,127.0.0.1,0,33345,36736,36751,0,::ffff:127.0.0.1,::ffff:127.0.0.1,0,33346,36736,74690,0,::ffff:127.0.0.1,::ffff:127.0.0.1,0,33347,36736,36749,0,
DATA,4,20180529235251,0,4263532,464027, 2,4181981,2060546,3,4181981,2060546, 4,4181981,2060546, 5,4181981,2060546, 6,4263221,464221, 7,418332,206023,8,4181232,2060232, 9,418123,206023, 10,41812323,202456