What are the data types in Python?

Description

To know about different data types in python.

Data:

  Data is a information about 
something.

  Its raw in nature.

  We need to convert the
 unstructured data(raw data)
 into a structured format
 in data pre-processing.

Data types in python:

  List

  Tuples

  Set

  Dictionaries

List:

  List is a collection of elements,
which is ordered and  changeable.

  We can add,change,delete
 an element in a list using  index position or inbuilt
 methods.

  Python lists are written with square 
brackets[].

Tuples:

  Tuples is a collection of 
elements,which is ordered and  unc
hangeable.

  Python tuples are written with 
round brackets.()

Set:

  Set is a collection which is unordered 
and unindexed.

  Python sets are written with curly 
brackets.{}

Dictionaries:

  Dictionaries is the most used 
python data type in data 
science.

  It used to store key:
value pair of data.

  We can call the key and values 
independently using  inbuilt methods 
d.key(),d.values().

  We can add,remove,change an  
element in a dictionary.

  Key may be a string and value 
may be a string.

#Python list

#creating the list1

list1=['sathish','sangeetha'
,'venkat','sheela','sudhakar']

#Creating the list2

list2=[23,24,25,22,21]

print("Python list")

#print the list1

print(list1)

#print the list2

print(list2)

print(type(list2))

print("\n")

#Python tuple

#creating the tuple1

tuple1=('sathish','sangeetha'
,'venkat','sheela','sudhakar')

#Creating the tuple2

tuple2=(23,24,25,22,21)

print("Python tuple")

#print the tuple1

print(tuple1)

#print the tuple2

print(tuple2)

print(type(tuple2))

print("\n")

#Python set

#creating the set1

set1={'sathish','sangeetha
','venkat','sheela','sudhakar'}

#Creating the set2

set2={23,24,25,22,21}

print("Python set")

#print the set1

print(set1)

#print the set2

print(set2)

print(type(set2))

print("\n")

#Python Dictionary

#creating the dictionary

dict1={'sathish':23,'sangeetha'
:22,'venkat':24,'sheela':26,'sudha kar'
:25}

print("Python dictionary")

#print the dictionary

print(dict1)

#Check the type of variable dict1

print(type(dict1))

print("\n")

#pandas library used for data analyse

import pandas as pd

#creating the dictionary having details

of employees in a #company

dict1={'name':['sathish',
'nandhini','sangee','venkat','sudhakar'],
' Age':[23,21,22,20,21],'salary'
:[100,50,150,250,300]}

#creating a data frame and pass the

dictionary elements.

df=pd.DataFrame(dict1)

#print the data frame.

print(df)

print("\n")

#pandas library used for data analyse

import pandas as pd

#Reading the data from a CSV file

data=pd.read_csv('/home/
soft23/soft23/Sathish/Pythonfiles/
Employee.csv')

#creating a data frame and
pass the data from the file

df=pd.DataFrame(data)

#print the data frame.

print(df)

Leave Comment

Your email address will not be published. Required fields are marked *

clear formSubmit