import pandas as pd
my_data=pd.read_excel("kw1_short.xlsx")
print(my_data)
This will display all 50 records from the excel file. Now using this code we will develop further code.
import pandas as pd
my_data=pd.read_excel("kw1_short.xlsx")
my_data=my_data[my_data.Query.str.contains('HTML',case=False)]
print(my_data)
Output is here
Query Clicks
6 marquee speed html 406
7 html calendar 387
8 html marquee speed 356
9 marquee html speed 341
10 calendar html code 326
12 html calendar code 289
18 calendar html 197
21 marquee behaviour in html 183
23 image button html 178
24 how to select multiple options from a drop dow... 172
29 html event calendar code generator 165
30 image button in html 164
32 html marquee behavior 127
38 paired tags in html 120
40 types of tags in html 117
print(my_data.Query.count())
Output of count()
15
print(my_data.Clicks.sum())
Ouptut
3528
print(my_data.Clicks.max())
print(my_data[my_data['Clicks']==my_data.Clicks.max()])
Output
406
Query Clicks
6 marquee speed html 406
Here 406 is the maximum click and the 6th row with Query marquee speed html generated the highest Clicks.
my_data['LENGTH']=my_data['Query'].str.len()
print(my_data.sort_values(by=['LENGTH']).iloc[0])
Output is here
Query html calendar
Clicks 387
length 13
As you can see the minimum length query is html calendar is of length 13. But as we are displaying one row only, we may miss if more than one column is having length equal to 13. We will modify the code to get all the rows having minimum length of query.
print(my_data[my_data['Query'].str.len()==my_data['Query'].str.len().min()])
Output is here
Query Clicks LENGTH
7 html calendar 387 13
18 calendar html 197 13
print(my_data[my_data['Query'].str.len()==my_data['Query'].str.len().max()])
Here is the output
Query Clicks
24 how to select multiple options from a drop dow... 172
Here is the full code. Lines are commented with descriptions, you can remove the comment and check the code.
import pandas as pd
my_data1=pd.read_excel("kw1_short.xlsx")
my_data=my_data1[my_data1.Query.str.contains('HTML',case=False)]
#print(my_data)
#my_data['LENGTH']=my_data['Query'].str.len()
#print(my_data)
#print(my_data.sort_values(by=['LENGTH']).iloc[0]) # shortest query ( one row only)
#print(my_data.Query.count()) # Total number of rows
#print(my_data.Clicks.sum()) # sum of clicks
#print(my_data.Clicks.max()) # maximum clicks
#print(my_data[my_data['Clicks']==my_data.Clicks.max()]) # row with maximum clicks
#print(my_data[my_data['Query'].str.len()==my_data['Query'].str.len().min()]) # shortest Query
#print(my_data[my_data['Query'].str.len()==my_data['Query'].str.len().max()]) # longest Query
Pandas
Pandas DataFrame Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.