Python Forum
Upload csv file as numbers (floating?) and extract element, row, and column
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Upload csv file as numbers (floating?) and extract element, row, and column
#1
Hello,

I've been trying for a couple days to upload a csv file as a 2D matrix of numerical values (e.g. 1+2=3) so that I can extract individual numbers, rows, and, columns. I am using numpy. The input csv file is has four rows and three columns.

This is as close as I've gotten:

import numpy as np
import csv 
with open('C:\\Users\\...\\matrix.csv') as File:  
    reader = csv.reader(File, delimiter=',')
    for data in reader:  
        data = np.matrix(data, dtype=float)
        x = data.shape        
        print (x)
This gives me four 1x3 matrices instead of a 4x3 matrix. Thoughts?

Thank you,
Ben
Reply


Messages In This Thread
Upload csv file as numbers (floating?) and extract element, row, and column - by bentaz - Mar-16-2018, 04:46 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Finding the median of a column in a huge CSV file markagregory 5 1,781 Jan-24-2023, 04:22 PM
Last Post: DeaD_EyE
  extract and plot data from a txt file usercat123 2 1,230 Apr-20-2022, 06:50 PM
Last Post: usercat123
  Filter data based on a value from another dataframe column and create a file using lo pawanmtm 1 4,282 Jul-15-2020, 06:20 PM
Last Post: pawanmtm
  How to print a column name in csv file Truman 1 4,427 Mar-31-2020, 03:34 AM
Last Post: Larz60+
  Change column names from a file Nidhesh 2 3,013 Jul-08-2019, 06:00 AM
Last Post: Nidhesh
  OpenCV - extract 1st frame out of a video file kerzol81 2 22,006 Nov-12-2018, 09:12 AM
Last Post: kerzol81
  copy one column from csv file and paste into xls file kprogrammer 0 4,378 Nov-03-2018, 04:03 PM
Last Post: kprogrammer
  Writing a floating point aifc file jandyman 1 2,620 Dec-29-2017, 07:48 PM
Last Post: Larz60+
  Extract data between two dates from a .csv file using Python 2.7 sujai_banerji 1 10,370 Nov-15-2017, 09:48 PM
Last Post: snippsat
  Identifying items in a csv file that also appear in a Text extract Jaynorth 17 17,498 Sep-21-2016, 10:51 PM
Last Post: Jaynorth

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020