0% found this document useful (0 votes)
3 views2 pages

Load and Display CSV in Python

The document provides Python code snippets for loading and displaying CSV file contents using NumPy. It demonstrates various methods to read the data, including skipping headers and displaying specific rows and columns. Additionally, it shows how to compute mean values for selected columns in the dataset.

Uploaded by

Ramesh Babu
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Load and Display CSV in Python

The document provides Python code snippets for loading and displaying CSV file contents using NumPy. It demonstrates various methods to read the data, including skipping headers and displaying specific rows and columns. Additionally, it shows how to compute mean values for selected columns in the dataset.

Uploaded by

Ramesh Babu
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

P1: Load CSVfile into Python program and display the contents

importnumpy as np
# Loadthe dataset
data =[Link]('C:\\Users\\IT RAMESH\\Desktop\\[Link]',
delimiter=',')
print("Without skipping header")
print(data)
data = [Link]('C:\\Users\\IT RAMESH\\Desktop\\[Link]',
delimiter=',', skip_header=1)
print("With skiped header")
print(data)
print("Display some columns only")
print(data[ :,[2, 3, 4]])

P3: Display data with text and row wise


import numpy as np
data = [Link]('C:\\Users\\IT RAMESH\\Desktop\\[Link]',
delimiter=',', names=True, dtype=None, encoding='utf-8')
print("Data with text in sheet ")
print(data)
print("Data displayed row wise")
for row in data:
print(row)

P2: Load CSV file into Python program and display contents
import numpy as np
#from io import StringIO
print("Disaply Entire CSV as it is")
arr = [Link]('C:\\Users\\IT RAMESH\\Desktop\\[Link]',
delimiter=",", dtype=str)
print(arr)
print("First 5 rows including heading ")
print(arr[:5])
print("Display 2 to 6 rows ")
print(arr[2:7])
print("columns 1 to 5 from csv")
print(arr[:,1:5])

P4: Display data in different kinds


import numpy as np
data=[Link]('C:\\Users\\IT RAMESH\\Desktop\\[Link]',
delimiter=",", dtype=str)
print("ORIGINAL DATA IS ")
IT-Ramesh 9848353570 1
print(data)

#print("Display data without heading")


ndata=[Link]('c:\\Users\\IT RAMESH\\Desktop\\[Link]',
delimiter=",", skiprows=1, dtype=str)
#print(ndata)

#print("2, 3, and 4 columns in csv in integer form")


idata = ndata[:, 2 : 5].astype(int)
#print(idata)

#print("SUM of M1 vlaues")
#print([Link](idata[:,0]))

#print("Mean value on each column")


print(data[0,:])
print([Link](idata, axis=0))
#print("Mean value on each Row")
#print(data[0,:])
#print([Link](idata, axis=1))

IT-Ramesh 9848353570 2

You might also like