0% found this document useful (0 votes)
6 views

2736118-Python Pandas

The document discusses using the pandas library in Python to work with data in DataFrames. It shows how to import data from files, manipulate and analyze the data, and export it to CSV files. Various pandas functions are demonstrated including reading, filtering, describing and replacing values in columns.

Uploaded by

Santhosh
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)
6 views

2736118-Python Pandas

The document discusses using the pandas library in Python to work with data in DataFrames. It shows how to import data from files, manipulate and analyze the data, and export it to CSV files. Various pandas functions are demonstrated including reading, filtering, describing and replacing values in columns.

Uploaded by

Santhosh
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
You are on page 1/ 2

import pandas

pandas.set_option("display.max_rows", None)
pandas.set_option("display.max_columns", None)
#pandas is third party library for executing tasks in simpler way
#In general the data we use in single dimension
#Files liks csv excel, json, db ---> to dimensional

# my_data = [["name","age"],["dhoni",33],["kohli",28]]
# print(my_data)
#
# my_data_frame = pandas.DataFrame(my_data)
# print(my_data_frame)

#Series --> 1 x
#DataFrame --> 2 X ---> 95
#Panels --> 3 x

#------------------Converting first rows as column name in pandas

# my_data = ["name","age"],["dhoni",33],["kohli",28]
# print(my_data)
# print(type(my_data))
# my_data_frame = pandas.DataFrame(my_data[1:],columns=my_data[0])
# print(my_data_frame)

# my_data = [("name","age"),("dhoni",33),("kohli",28)]
# print(my_data)
# print(type(my_data))
# my_data_frame = pandas.DataFrame(my_data[1:],columns=my_data[0])
# print(my_data_frame)

# my_data = {"name":("dhoni","kohli"),"age":[33,44]}
# print(my_data)
# print(type(my_data))
#
# my_data_frame = pandas.DataFrame(my_data)
# print(my_data_frame)
# print(dir(my_data_frame))
#
# #index = None will no show index or row number as part of the sheet in CSV
# #columns = None will have no affect on the columns
# my_data_frame.to_csv("shiva.csv", index=None,columns=None)

# my_data = [["name","age"],["dhoni",33],["kohli",28]]
# print(my_data)
# print(type(my_data))
#
# my_data_frame = pandas.DataFrame(my_data)
# print(my_data_frame)
# print(dir(my_data_frame))
#
#
# #index = None will no show index or row number as part of the sheet in CSV
# #columns = None will have no affect on the columns
# #header = False is used to remove the first column entity from the given table
# my_data_frame.to_csv("shiva.csv",index=False,header=False)

#task --> Remove the columns from given output of csv file

# my_data = pandas.read_csv(r"C:\Users\jegadesh\Documents\Dell\loan_data_1.csv")
#
# #below syntax displays all the columns
# #pandas.set_option('display.max_columns',None)
#
# #print(my_data) #returns all the data
#
# #print(my_data.head()) #it returns first five dta of the input
# #print(my_data.tail()) #it returns last five data of the input
#
# print(my_data.tail(16))

#below 5 lines of code is to print specific columns, specific rows (staring and ending rows)

# columns_to_read = ['Loan_ID','Gender','Married']
# staring = 2
# ending = 19
# my_data = pandas.read_csv(r"C:\Users\jegadesh\Documents\Dell\loan_data_1.csv",usecols=columns_to_read, nrows=ending)
# print(my_data)

#Finding out stat of the files or data


# my_data = pandas.read_csv(r"C:\Users\jegadesh\Documents\Dell\loan_data_1.csv")
# # print(my_data)
# # print(my_data.describe())
# # print(my_data.ndim)
# # print(my_data.hist)
# print(my_data.info)

#loc and iloc

#Changing column name


# my_data = pandas.read_csv(r"C:\Users\jegadesh\Documents\Dell\loan_data_1.csv")
# print(my_data.head(2))
# my_data.rename(columns={'Loan_Status': 'Status'},inplace=True)
# print(my_data.head(2))

#replace function in pandas

#my_data = pandas.read_csv(r"C:\Users\jegadesh\Documents\Dell\loan_data_1.csv")

# my_data['Married'].replace("Yes", 1, inplace=True)
# print(my_data.head())

# my_data['CoapplicantIncome'].replace(0, "NA", inplace=True)


# print(my_data.head())

# my_data.replace(0, "NA", inplace=True)


# print(my_data.head())

# my_data.replace({"Male":"GentleMen"}, inplace=True)
# print(my_data)
#
# my_data.to_csv("sivanesan.csv")

#my_data = pandas.read_csv(r"C:\Users\jegadesh\Documents\Dell\loan_data_1.csv")

#Below three lines will throw error as we cant divide anything incomon in list
# my_list = [4,8,12,20]
# division_output = my_list/4
# print(division_output)

# my_list = [4,8,12,20]
# output = []
# for x in my_list:
# output.append(x/4)
# print(output)

#List comprehension
# my_list = [4,8,12,20]
# output = [x/4 for x in my_list]
# print(output)

import numpy
# my_list = numpy.array([4,8,12,20])/4
# print(my_list)

# data_array = numpy.arange(10)
# print(data_array)
#
# random_number = [x for x in range(10)]
# print(random_number)

# data_array = numpy.linspace(0,10,4)
# print(data_array)

# data_array_random = numpy.random.rand()
# print(data_array_random)

data_array_random = numpy.random.uniform(low=70, high = 100, size=(5,))


print(data_array_random)

You might also like