How does python pandas implement functions like left or right in excel?
This article mainly explains "how to implement python pandas similar to the left or right function in excel". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how python pandas implements functions similar to left or right in excel".
With regard to this problem, I think it is most convenient to apply slicing after calling the str function.
Examples are as follows
> import pandas as pd
> import numpy as np
> df=pd.read_excel (ringing DGV >
> df
Name score
0 bob_B 45
1 jiken_A 67
# get the first three letters of the name column
> df ['nam2'] = df.name.str [: 3]
> df
Name score nam2
0 bob_B 45 bob
1 jiken_A 67 jik
# get the last three letters of the name column
> df ['nam1'] = df.name.str [- 3:]
> df
Name score nam1
0 bob_B 45 b_B
1 jiken_A 67 n_A
In fact, it is easy to solve as long as you have mastered the str function and are familiar with slicing.
At this point, I believe you have a deeper understanding of "how to implement python pandas similar to the left or right function in excel". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!