slice

How do I rotate a string to the right until every letter has been rotated?

How do I rotate a string to the right until every letter has been rotated? Question: I want to rotate a word to the right, so that every letter has passed. What I tried to do is make a function. It looks like this (yeah yeah ik lmao): word = "Abobus"; length = len(word); n …

Total answers: 4

RGGB (x,y) –> RGB = (x/2,y/2,3)

RGGB (x,y) –> RGB = (x/2,y/2,3) Question: The output of a camerasensor is SRGGB12. import numpy as np rggb = np.array([[‘R’, ‘G’, ‘R’, ‘G’], [‘G’, ‘B’, ‘G’, ‘B’], [‘R’, ‘G’, ‘R’, ‘G’], [‘G’, ‘B’, ‘G’, ‘B’]]) test2 = np.chararray((3, 4, 4)) test2[:] = ” test2[2,::2, ::2] = rggb[1::2, 1::2] # blue test2[1,1::2, ::2] = rggb[0::2, …

Total answers: 2

Check if the first and the last letter of the string are the same(Python)

Check if the first and the last letter of the string are the same(Python) Question: I have a list of strings and I wanted to count how many words are having same first and last letter: strings = ["Ana", "Alice", "Bob", "Alex", "Alexandra"] count = 0 for word in strings: if word[0] == word[-1]: count …

Total answers: 2

python pandas: using slice to build a multiindex slicing in pandas

python pandas: using slice to build a multiindex slicing in pandas Question: I have a double Multiindex dataframe as follows. I slice the rows with idx = pd.IndexSlice but I dont know how to do the same with the columns so provided this data: df = pd.DataFrame(data=pd.DataFrame(data=np.random.randint(0, 10, size=(9, 5)))) # rows list1 = [‘2021-01-01′,’2022-02-01′,’2022-03-01’] …

Total answers: 1

Slicing, list assignment and deep/shallow copy

Slicing, list assignment and deep/shallow copy Question: From the problem ‘Removes any element from L1 that also occurs in L2’ first case def removeDups(L1, L2): L3 = L1[:] for e1 in L3: print(‘L3’ + str(L3)) print(‘L1: ‘ + str(L1)) if e1 in L2: L1.remove(e1) L1 = [1,2,3,4] L2 = [1,2,5,6] removeDups(L1, L2) Output: L3[1, 2, …

Total answers: 3

How to dynamically name dataframes?

How to dynamically name dataframes? Question: Suppose I have a dataframe as follows: s = df.head().to_dict() print(s) {‘BoP transfers’: {1998: 12.346282212735618, 1999: 19.06438060024298, 2000: 18.24888031473687, 2001: 24.860019912667006, 2002: 32.38242225822908}, ‘Current balance’: {1998: -6.7953, 1999: -2.9895, 2000: -3.9694, 2001: 1.1716, 2002: 5.7433}, ‘Domestic demand’: {1998: 106.8610389799729, 1999: 104.70302507466538, 2000: 104.59254229534136, 2001: 103.83532232336977, 2002: 102.81709401489702}, ‘Effective exchange …

Total answers: 1

first argument must be an iterable of pandas objects, you passed an object of type "Series"

first argument must be an iterable of pandas objects, you passed an object of type "Series" Question: I have the following dataframe: s = df.head().to_dict() print(s) {‘BoP transfers’: {1998: 12.346282212735618, 1999: 19.06438060024298, 2000: 18.24888031473687, 2001: 24.860019912667006, 2002: 32.38242225822908}, ‘Current balance’: {1998: -6.7953, 1999: -2.9895, 2000: -3.9694, 2001: 1.1716, 2002: 5.7433}, ‘Domestic demand’: {1998: 106.8610389799729, 1999: …

Total answers: 1

Extracting 2 digits numbers from string

Extracting 2 digits numbers from string Question: I have a file which contains string, from every string I need to append to my list every 2 digit number. Here’s the file content: https://pastebin.com/N6gHRaVA I need to iterate every string and check if string on index[i] and on index[i+1] is digit, if yes, append those digits …

Total answers: 4

How can I solve this double sub-string and astype problem

How can I solve this double sub-string and astype problem Question: In this case I have a problem with this: Im trying to split a column "UbicaciĆ³n Finalizada" in two, but I have a problem with a "," string, I can’t take it out and that make some problems in the after code because I …

Total answers: 1

File Names Chain in python

File Names Chain in python Question: I CANNOT USE ANY IMPORTED LIBRARY. I have this task where I have some directories containing some files; every file contains, besides some words, the name of the next file to be opened, in its first line. Once every word of every files contained in a directory is opened, …

Total answers: 2