I will write down what I did not know, which is the basics of Python, in the order I knew it.
Function as an argument Add \ * (star) to make a tuple type argument Add \ ** (double star) to make dictionary type argument Example)
def print_text(*x):
print(x)
def print_text(**x):
print(x)
df = df[~df.duplicated()]
#Either one is ok
list1.extend(list2)
list1 = list1 + list2
#But this is an error
list1 = list1.extend(list2)
map I use this quite often
###For example, when making a list like for###
def plus_one(i):
return i+1
list1 = [1,2,3]
#Since the return value of map is an iterator, enclose it in list
list2 = list(map(puls_one,list1))
#list2 = [2,3,4]
#You can use a lambda expression
#lambda.ver
list2 = list(map(lambda x : x+1,list1))
When processing or adding to a column with a data frame
for index, item in df.iterrows()
It takes a lot of time to turn it with (even if you avoid the generation of Series or take some measures).
Instead, once
list = list(map(func,index_list))
Make a list of the columns you want to dig in with, and later
df.assign(new_low = list)
Is much faster.
I think so from the experience of running with 40 million lines of df (laughs)
Recommended Posts