How to change column names from numbers to names [closed]
First, move the non-date columns in to the index, then use replace and reset_index: df = df.set_index(‘CashFlows’) df = df.rename(columns=lambda x: ‘year_’+str(x.year))
First, move the non-date columns in to the index, then use replace and reset_index: df = df.set_index(‘CashFlows’) df = df.rename(columns=lambda x: ‘year_’+str(x.year))
You need to append to code each time through the loop, not assign to it. You shouldn’t reinitialize it in the loop, and the return statement should be after the loop. And if you want a 2-dimensional list, you need to wrap the concatenations in another list. However, the loop can be replaced completely with … Read more
it seems like you have a list of strings and you want to sort them numerically. to do this you need to tell sort that it needs to sort each element as if it were an int. my_nums = [’22’, ’25’, ’75’, ’52’, ’70’, ’14’, ‘5’, ’60’, ’81’, ’83’, ’72’, ‘2’, ’36’, ’78’, ’10’, ’65’, … Read more
Because none of your patterns ever match, the loop will keep incrementing the idx until it goes over the bounds of the tuple. The reason for no match, is that you have a small error in your last regex pattern. This: r'([\w\D]+) (\d{2}) , (\d{4})’) should be: r'([\w\D]+) (\d{2}), (\d{4})’) After fixing this I’m able … Read more
You can use urllib2 and socket module for the task. import socket from urllib2 import urlopen, URLError, HTTPError socket.setdefaulttimeout( 23 ) # timeout in seconds url=”http://google.com/” try : response = urlopen( url ) except HTTPError, e: print ‘The server couldn\’t fulfill the request. Reason:’, str(e.code) except URLError, e: print ‘We failed to reach a server. … Read more
You can just add, while computer1 in GuessList: computer1 = randint(0, 5) After your computer1 = randint(0, 5). You might have to remove your GuessList = [ ] because that will reset your GuessList each time. Instead, you should have that at the very start of your code and leave the append statement. Or you … Read more
The identation is incorrect and causing the error. Also, the and true does not serve anything there. You can try the following code: a = 200 b = 33 c = 500 if a < b: print(“Both conditions are True”) elif a > b: print(“f”)
The issue is most probably because of versions 1.7 have been stripped of all self bot methods. If you want to Selfbot you either go with an outdated, unsupported and unmaintained library or interact directly with the API. In any case you’re breaking ToS and you won’t receive any support on any official channel. There … Read more
To solve your problem you need a parser. There are various libraries that can be used for parsing in Python, see Python parsing tools by SO veteran Ned Batchelder for a list of what’s available. However, your data format isn’t too complicated, so it’s easy enough to write a simple parser that doesn’t rely on … Read more
Another way, assuming you can sort the list is the following original_l = [1,2,6,4,9,3] my_l = [ [index, item] for item,index in zip(original_l, range(0,len(original_l)))] my_l_sort = sorted(my_l, key=lambda x: x[1]) start_i = 0 end_i = len(my_l_sort)-1 result = [] target = 7 while start_i < end_i: if my_l_sort[start_i][1] + my_l_sort[end_i][1] == target: result.append([my_l_sort[start_i][0], my_l_sort[end_i][0]]) break … Read more