• May 2, 2025

Python

Python Installation

There are two ways to download and install Python

  1. Download Python from its official website. You have to manually install libraries.
  2. Download Anaconda. It comes with python and also popular python modules.

Useful commands:

pip listTo get the installed packages
python – – versionTo check the python version
pip show pandasTo display Pandas Version
print(pandas.__version__)To display Pandas Version
pandas.show_versions()It comprises info about hosting OS, Pandas version, and versions of other installed packages
pip install pandasTo upgrade the Pandas module

pip install – – upgrade pandas – – user
To upgrade the Pandas module
conda – – versionTo display conda version
conda env listTo display conda environment list
conda activate baseTo activate base conda environment
conda deactivateDeactivate all conda environments

Python Datatypes

TypeDescriptionSample ValuesCreateAccess Variable & its Value
stringordered, immutable, collection datatype‘a’, ‘london’, ‘lon123’ , ‘how are you’‘a’
or
“he’s”
Refer appendix below
listordered, mutable, collection datatype

list can have different datatype

Accessing element in a list by referring its index
[‘a’, 1, 3.5, ‘Hello’]list( )
or
[ ]
e.g. var_lst[0]
out: ‘a’

Refer appendix for more details
tupleordered, immutable, collection datatype

often used for objects belong together.

can’t create a tuple with single value i.e. then it is called as string.
To create a tuple with single value add comma at the end. e.g. (‘a’,)

When passing multiple values to the variable then automatically it create a tuple.
( ) – optional
setunordered, mutable, no duplicate set( )
or
{ }
dictionaryunordered, mutable, collection datatype
key value pair

mutable – value of the key can be overwrritten
dict_var={“name”:”Ravi”,
“location”:”London”}

or

dict_var=dict(name=”Ravi”,
location=”London”)

Note: 2nd method don’t need double quotes and “=” symbol used instead of “:”
dict()
or
{ : }
dict_var[“name”]

If no key then we get key don’t exist error

or

dict_var.get(“name”)

If no key nothing gets outputted and won’t cause any key error.
Note: Mutable – can change / changeable, and immutable is opposite to mutable.

Pandas Datatypes

Int64Int
float64Float
objectstr or mixed (e.g. numeric and non numeric)
booleanTrue/False

Appendix:

Accessing String variable sample:


List and also Error handling

Note: Some of the topics listed to be updated later

Python List

Leave a Reply

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