Python Programming in Hindi

I am facing this issue ,Can someone help me with this ? Python error: string index out of range python

What does %s mean in Python? And what does the following bit of code do?
%s is used to format the string syntax and it was taken from C.

how to convert a pandas dataframe into a NumPy array.

I am getting an error when importing pytorch.I have already installed pytorch using anaconda.Here is the error:modulenotfounderror: no module named ‘torch’

import torch

ModuleNotFoundError: No module named ‘torch’

I am getting an error after all the elements are printed when i run my python script:”list index out of range in python”:here is the code

list1 = [‘Apple’, ‘Banana’, ‘Orange’]
i=0
while i <= len(list1):
print(list_fruits[i])
i += 1

IndentationError: expected an indented block is what the console returns when my code is exactly what is on a video lesson

name = input("What’s your name? ")

if name == “Kris”:

print(name + " is a lumberjack and he is ok!")

else:

print(name + " sleeps all night and " + name + “works all day!”)

The string index out of range comes when the index you are trying to access does not exist.

The value of i which you are using to access the list is going beyond the number of elements in the list which is causing the list index out of range error.You can correct the code by changing the condition of while loop like this:

list1 = [‘Apple’, ‘Banana’, ‘Orange’]
i=0
while i < len(list1):
print(list_fruits[i])
i += 1

You should properly install pytorch using anaconda.The proper way to install pytorch to anaconda is following

conda install -c pytorch pytorch

First activate your conda profile with “source activate {your_profile}” if not already done and then use the above command.

Python requires formatting of blocks with indentation which basically means that you have to leave spaces before writing a line of code.The code lines belonging to same block must have same exact indentation which means the there must be equal number of spaces before each line of a block.So for you code,the correct formatting is like this:

if name == “Kris”:

print(name + " is a lumberjack and he is ok!")

else:

print(name + " sleeps all night and " + name + “works all day!”)

Putting in an extra space or leaving one out where it is needed will surely generate an error message

The error message IndentationError: expected an indented block would seem to indicate that you have an indentation error which is also sometimes caused by a mix of tabs and spaces. The indentation can be any consistent white space . It is recommended to use 4 spaces for indentation in Python, tabulation or a different number of spaces may work, but it is also known to cause trouble at times. Tabs are a bad idea because they may create different amount if spacing in different editors .

%s is used to format the string syntax and it was taken from C.

I am trying to execute following code :

Given a getStr() function, write the necessary sequence of operations to transform the string (containing three literals) in such a way that every literal is tripled? respectively.

def getstr(s) :
result = 0
for i in s :
result = result + int(s[i] * 3)
#strlen = len(s)
return result

print(getstr(“abc”))

And it gives me a following error

How to convert string to JSON using Python?

How to display column names of Pandas Dataframe?

What is inplace in python and how does it affect my data it?Here is my code where I am using it.

df.dropna( inplace=True)

I have been getting this error: Unexpected indent in python? I have used indentation but till I am getting this error.

How to change directory in python?

What is the difference between sort() and sorted() methods in python?

You can use os module to do so,here is an example to change directory to a certain path.

os.chdir(path)

The path should be passed as a string,more preferably a raw string.

When you set inplace as True,the data in your case df is changed, we can say that it permanently changed your dataframe df.
On the other hand when you use inplace=False,the change does not occur in the original data df.Instead it performs the operation and returns a copy of the object, so you’d use:

df1=df.dropna(inplace=False)

Now your original data is unchanged.Sometimes you want the copy of your original dataframe and it can be useful then.