When loc and iloc can give same output? Let’s take an example: what is the output of loc[1] for the above Data Frame? When we use iloc[1], the output is: That is, the output is same for both loc and iloc. Please note: We need to provide label as input for data filtering for loc.Continue reading “Random Python Question #6”
Tag Archives: random python
Python Random Tips #8
This is not a Python Starter Tutorial but advanced Python Tips in a Random Order. How do we concatenate multiple lines from a file? #1 Here is one way: Note: If we need we can add one space after each line (if required), otherwise we have just concatenated 3 lines from a file into aContinue reading “Python Random Tips #8”
Python Random Tips #7
This is not a Python Starter Tutorial but advanced Python Tips in a Random Order. In this section, let us see some quick questions & answers with Python code examples: #1 How to remove the last element from a Python list? #2 append() vs entend()? Append() adds the element to the end of the list.Continue reading “Python Random Tips #7”
Random Python Questions #3
Why the below result is ‘false‘?
Random Python Questions #1
What is the result of the below Python code: from collections import Counterinput_dictionary = {‘a’:5, ‘b’:3, ‘c’: 1, ‘b’:2}print(Counter(input_dictionary)) Result:Counter({‘a’: 5, ‘b’: 2, ‘c’: 1}) Question: Even-though we have 2 values for the key ‘b’ in “input_dictionary”, the result has only one ‘b’ key/value pair. Do you know why? What’s the reason?