Find the best tutors and institutes for Python Training

Find Best Python Training classes

Please select a Category.

Please select a Locality.

No matching category found.

No matching Locality found.

Outside India?

Search for topics

Python Training Updates

Ask a Question

All

Lessons

Discussion

Lesson Posted on 29 Mar IT Courses/Programming Languages/Python IT Courses

Python Important Operation Formats and Sytnax.

Silvia Priya

Experienced datawarehouse professional for 7.5 years. Certified Big data-Hadoop and Python Trainer. I...

Hello Python Enthusiast, Though Python is considered as one of the easisest language to learn in the market, many freshers and beginners will find great difficulty in understansing the syntax and also how to achieve a operation under a given situation. To make that more easier and clearer for you,... read more

 Hello Python Enthusiast,

Though Python is considered as one of the easisest language to learn in the market, many freshers and beginners will find great difficulty in understansing the syntax and also how to achieve a operation under a given situation.

To make that more easier and clearer for you, im posting some of the important operations and how to achieve it with their syntax.

Understandings

  • Any word enclosed inside the <> means it is a general form, you can replace it with your dataframe or column name or index name depending upon what mentioned in the syntax.
  • Where ever [] or single quotes or double quotes are mentioned use it as it is.
  • Words mentioned without any <> symbols represents the keywords , so use as it is.

Come, lets learn!!

Basic operations in pandas

 

  • Replace a column value in a dataframe

If you want single value to be replaced to single value or multiple values to be replaced by multiple values follow the below statement accordingly.

<Dataframe>[‘<Columnname>’]=<Dataframe>[‘<Columnname>’].replace(‘<value1>’,’<newvalue>’)

<Dataframe>[‘<Columnname>’]

=<Dataframe>[‘<Columnname>’].replace([‘<value1>’,’<value2>’],’<newvalue>’)

 

  • To read row by row and index by index in pandas

Reading the rows and the index postitions can be done using the following statements.

for <index>,<row> in <dataframe>.iterrows():

               print(<row>) #prints the rows inside the dataframe

               print(<index>) #prints the index value of that row

 

  • To concatenate multiple dataframes into a single one

To combine three data frames into one single dataframe.

<Combined_dataframe>=pd.concat([<dataframe1>,<dataframe2>,<dataframe3>])

All the dataframes which we are planning to combine must be put inside the list[] in concat function.

 

  • To view the top 5 lines of a dataframe

To print the top 5 lines of the dataframe.

<dataframe>.head()

 

  • To find out the columns having null values in a dataframe

To find the columns holding null values in it.

<null_columns> = <dataframe>.columns[<dataframe>.isnull().any()]

Isnull() - checks for null values

Any() - even if one row has null value also take that column

Now the null_columns  will contain a list of columns having null values in that data frame.

 

  • To find out the sum of null values in every column in a dataframe

How many null values a column holds can be identified by using the below format.

<dataframe>[‘<null_columns>’].isnull().sum()

 Apply the isnull() check on the columns identified as having null values and perform a sum on it.

 

  • To find out any specific column is having  null values  in it

To check whether any specific column is having null value in it or not.

<dataframe>[<dataframe>[“<column name>”].isnull()]

 To check whether the specified column name is having any null values in the dataframe.

 

  • To find out a row which contains atleast one null value in it

Basically the property axis=1 represents the column names in the dataframe and axis=0 represents the row names in the dataframe.

<dataframe>[<dataframe>.isnull().any(axis=1)]

To check whether any value is null on any one of the column in the dataframe, if so that complete row will be returned.

 

  • To replace a null value in a column with some other value

To replace the null value in a column with some other value use fillna 

<dataframe>[‘<columnname>’]=<dataframe>[‘<columnname>’].fillna(‘<value to replace>’)

 

What-ever posted above are about the functions used under the pandas library in python, similarly will post more about the basic python syntaxes and libraries like numpy,matplotlib etc.

 

Thank you!!

read less
Comments
Dislike Bookmark Share

Answered on 01 Apr IT Courses/Programming Languages/Python

Chitra J.

Tutor

There is an option to contact customer service. Click customer service to find the response or send email to : support @ urbanpro.com Thanks Chitra S
Answers 3 Comments
Dislike Bookmark Share

Answered on 01 Apr IT Courses/Programming Languages/Python

Where is there no Sweden in the list of locations?

Chitra J.

Tutor

There is an option to contact customer service. Click customer service to find the response or send email to : support @ urbanpro.com Thanks Chitra S
Answers 1 Comments
Dislike Bookmark Share

Overview

Questions 1.2 k

Lessons 65

Total Shares  

+ Follow 37,792 Followers

Lesson Posted on 16/11/2018 IT Courses/Programming Languages/Python

Build an interactive Dictionary using Python 3.x

Biswanath Banerjee

I have 20 years of solid technology experience , worked in various IT MNCs like IBM, Tech Mahindra, AT&T,...

I have downloaded a 5MB data base consisting of words and their meanings in a json file . I want to write a python progrsm which will ask the user to enter a word and then the program will search through the database and retuen back the meaning of the word . There can be instances when there are two... read more

 I have downloaded a 5MB data base consisting of words and their meanings in a json file . I want to write a python progrsm which will ask the user to enter a word and then the program will search through the database and retuen back the meaning of the word . There can be instances when there are two or three different meanings for a word. The program will display all the different meanings of the word.

I wanted to make the program little intelligent. What if the user spells he word incorrectly while entering the word? Suppose he wants to know the meaning of 'crowd' but by mistake he types in 'crowded'. The system will be intelligent enough to suggest few words nearest to the word 'crowdd' which he has typed and let the user choose the right word which he meant from the list of suggesstions.

Also , there are checks for cases - upper case, lower case etc.

Let us see the code now and then run the program to see the outputs:

Here is the python code which you have been eaiting for so long:

import json
from difflib import get_close_matches

data = json.load(open("data.json"))

print(data)

def translate(w):
w = w.lower()
if w in data:
return data[w]
if w in data:
return data[w]
elif w.title() in data: # user entered "maryland" will check for "Maryland" as well
return data[w.title()]
elif w.upper() in data:
return data[w.upper()]
elif len(get_close_matches(w,data.keys()))>0:
yn= input("Did you mean %s instead?. EnterY if yes, or N if no: "% get_close_matches(w,data.keys())[0])
if yn=='Y':
return data[get_close_matches(w,data.keys())[0]]
elif yn =='N':
return("the word does not exist")

else:
return ('We did not understand your entry')
else:
return("the word does not exist")
word = input("Enter word")
output =translate(word)
if type(output) == list:
for item in output:
print(item)
else:
print(output)

Let us test out different scenarios now :

Input: data["crowd"]

Output: ['A large number of people united for some specific purpose.', 'A crowd of people pressed close together in a small space.', '6-string musical instrument of Welsh or Irish origin and played with a bow.', 'A large group of people.', 'To cause to herd, drive, or crowd together.', 'To fill or occupy in a small space to the point of overflowing.', 'To gather together in large numbers.']

Input:

Enter word crowdd
Output:Did you mean crowded instead?. EnterY if yes, or N if no: 
Input: N
Output: the word does not exist

Another scenario. Suppose the User does not type the whole word but abbreviation like 'USA' or 'UK'.
How does our dictionary program find out the meaning in such case?
Input: Let us try out: Enter word UK
Output: A country in Western Europe (comprising Wales, Scotland, England and Northern Ireland) with the capital London.

This is a simple program to show you how to write simple Applications using Python.
Stay tuned to my Lessons. Next Lesson I will show you how to write another interesting interactive application
using Python.
read less
Comments
Dislike Bookmark Share

Answered on 21/12/2018 IT Courses/Java IT Courses/Programming Languages/Python

Madhavi

Python is one of the most used programming language than Java. With the recent Popularity of the Machine learning, Artificial intelligence and Data science Python takes the first place of the Top 5 programming languages today. Python is a very simple and begginer friendly language.Its easy to learn and... read more

Python is one of the most used programming language than Java.

With the recent Popularity of the Machine learning, Artificial intelligence and Data science Python takes the first place of the Top 5 programming languages today.

Python is a very simple and begginer friendly language.Its easy to learn and follow compared to any other language.

Python is interpreted whereas Java is compiled programming...

Python is a high level programming language with portability and object oriented programming. It has large number of standard libraries which makes the developer life easy compared to Java

Python is dynamic data types whereas Java is static.

Python has a wide range of applications like Web development, Mathematical computations and GUI.

Java is the best when working on Mobile applications compared to Python.

read less
Answers 5 Comments
Dislike Bookmark Share

Top Contributors

Connect with Expert Tutors & Institutes for Python

Answered on 02/12/2018 IT Courses/Programming Languages/Python

Pramod M.

Python trainer who trained around 500 students and help them secure a job

Python is best language to start with...ease of coding and reading in python makes amateur programmer like you to understand the concepts of programming....but my suggestion is dont learn just to learn it I mean do not learn the theory aspects learn the practical aspects like applying the concepts and... read more

Python is best language to start with...ease of coding and reading in python makes amateur programmer like you to understand the concepts of programming....but my suggestion is dont learn just to learn it I mean do not learn the theory aspects learn the practical aspects like applying the concepts and get 2 mini projects done in python because that is how many of our ECE students got jobs in TCS and Wipro.

read less
Answers 6 Comments
Dislike Bookmark Share

Answered on 26/11/2018 IT Courses/Programming Languages/Python

Which is the best book for the Python OOPS concept?

JOSHUA CHARLES

Tutor

The best book you can read is by O”Reilly
Answers 1 Comments
Dislike Bookmark Share

Answered on 11/12/2018 IT Courses/Programming Languages/Python

How can I print perfect numbers in a given range in Python?

Gayathri J.

def print_perfect_nums(start, end): for i in range(start, end + 1): sum1 = 0 for x in range(1, i): # Check if a divisor, if it is, add to sum if(i % x == 0): sum1 = sum1 + x if (sum1 == i): print(i) print_perfect_nums(1, 300)Perfect number is sum of... read more
def print_perfect_nums(start, end):
   for i in range(start, end + 1):
   sum1 = 0
   for x in range(1, i):
      # Check if a divisor, if it is, add to sum
      if(i % x == 0):
         sum1 = sum1 + x
         if (sum1 == i):
            print(i)
print_perfect_nums(1, 300)

Perfect number is sum of the divisorsa of the number is equal to the same number eg 6 divisors
are 1,2,3
read less
Answers 1 Comments
Dislike Bookmark Share

Answered on 09/12/2018 IT Courses/Programming Languages/Python

What does "self" mean in python class? Why do we need it?

Santosh Kumar

Imagine a situation. You stay in a big home with family members cosy and comfortabily (Class in Programming world). Now here comes your American born cousin for a visit, He does not know what is where, How everything works in your home. Your cousin wants to perform some activites (Call some functions... read more

Imagine a situation.

You stay in a big home with family members cosy and comfortabily (Class in Programming world). Now here comes your American born cousin for a visit, He does not know what is where, How everything works in your home.

Your cousin wants to perform some activites  (Call some functions in Programming world).

1. Wants to go out in Car.

2. Wants to cook.

You are always with him and ensure all the necessity are there so that he can perform all these activites.

You always that guiding force that helps him.

YOU in this case is that "self" object.

Similarly in Python class, when a member function is called by an instance of that class.

Function which is being called has a reference to itself called SELF which can access the member variables and other member function through the SELF.

So every member function in class when called has invisible SELF object which points to current calling object.

In the same way You cousin is able to do all the activities with the help of you.

 

For more details and deeper python programming constructs, Join my classes.

Santosh

read less
Answers 1 Comments
Dislike Bookmark Share

About UrbanPro

UrbanPro.com helps you to connect with the best Python Training classes in India. Post Your Requirement today and get connected.

x

Ask a Question

Please enter your Question

Please select a Tag

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 25 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 6.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more