Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

Monday 4 October 2021

Python Project [An application to save any random article from Wikipedia to a text file].


An application to save any random article from Wikipedia to a text file.



Output of the project






Source Code: 


from bs4 import BeautifulSoup
import requests

# Trying to open a random wikipedia article
# Special:Random opens random articles
res = requests.get("https://en.wikipedia.org/wiki/Special:Random")
res.raise_for_status()

# pip install htmlparser
wiki = BeautifulSoup(res.text, "html.parser")

r = open("random_wiki.txt", "w+", encoding='utf-8')

# Adding the heading to the text file
heading = wiki.find("h1").text

r.write(heading + "\n")
for i in wiki.select("p"):
    # Optional Printing of text
    # print(i.getText())
    r.write(i.getText())

r.close()
print("File Saved as random_wiki.txt")










Join us: https://t.me/jupyter_python

Program that converts arrays into a list, loops through the list to form a string using the chr() function




Input :


#Program that converts arrays into a list, loops through the list to form a string using the chr() function
#clcoding.com
import numpy as np
def ord_to_character(words = ""):
    
    x = np.array([112,121,134,123,32,96,34,56,67,111,98,97,119,105,113])
    
    y = np.array([78,90,104,123,132,53,34,56,97,116,98,27,119,77,117,12])
    
    z = np.array([111,112,134,123,21,32,108,106,89,70,80,103,103,120,121])
    
    letters = x.tolist() + y.tolist()  + z.tolist()
    
    for letter in letters:
        words += chr(letter)
        
        
    return words 


sentence = ord_to_character()
print(sentence)
    
Output :


py†{ `"8CobawiqNZh{„5"8atbwMuop†{ ljYFPggxy



Join us: https://t.me/jupyter_python

Plotting a colourful Scatter Plot using Matplotlib








from matplotlib import pyplot as plt

x = [10,20,30,40,50]
y = [200,300,100,400,500]
colors=[70,20,80,10,50]
sizes=[100,50,300,250,150]

plt.scatter(x,y,c=colors,s=sizes,cmap="Accent",alpha=1.0)
plt.colorbar()
plt.show





Join us: https://t.me/jupyter_python

Plotting Histogram using Pyplot







from matplotlib import pyplot as plt 

marks=[90,50,40,60,55,44,30,10,34,84]
grade_intervals=[0,35,70,100]
plt.title("Student Grades")
plt.hist(marks,grade_intervals,histtype="bar",rwidth=0.5,facecolor="blue")
plt.xticks([0,35,70,100])
plt.xlabel("Percentage")
plt.ylabel("No. of Students")
plt.show()


Join us: https://t.me/jupyter_python

Plotting Colourful Pie Chart In MatPlotlib




from matplotlib import pyplot as plt 

student_performance = ["Excellent","Good","Average","Poor"]
student_values = [15,25,12,8]
plt.figure(figsize=(7,10))
plt.pie(student_values,labels=student_performance,startangle=90,
        explode=[0.2,0,0,0],shadow=True,colors=["black","blue","yellow","red"],autopct="%2.1f%%")


plt.legend(title="Perfomances")
plt.show




Wednesday 23 June 2021

HANDLING MISSING DATA (FillNa) IN PANDAS



Firstly, we are importing an excel sheet as a DataFrame,
 

import pandas as pd
ds = pd.read_excel("C:\\Users\\mahes\\OneDrive\\Documents\\Students.xlsx")
dt = pd.DataFrame(ds)
print(dt)








Now, Let's perform some operations related to FillNa()











Join us: https://t.me/jupyter_python

HANDLING MISSING DATA (dropna) IN PANDAS


Firstly, we are importing an excel sheet as a DataFrame,
 

import pandas as pd
ds = pd.read_excel("C:\\Users\\mahes\\OneDrive\\Documents\\Students.xlsx")
dt = pd.DataFrame(ds)
print(dt)






Now, Let's perform some operations related to DROPNA


















Join us: https://t.me/jupyter_python

ILOC[ ] IN PANDAS - PYTHON

Firstly, we are importing an excel sheet as a DataFrame,
 
import pandas as pd

ds = pd.read_excel("C:\\Users\\mahes\\OneDrive\\Documents\\Students.xlsx")

dt = pd.DataFrame(ds)






Now, Let's perform some operations related to ILOC 












Join us: https://t.me/jupyter_python

LOC[ ] IN PANDAS - PYTHON



LOC[ ] IN PANDAS

Firstly, we are importing an excel sheet as a DataFrame,
 
import pandas as pd

ds = pd.read_excel("C:\\Users\\mahes\\OneDrive\\Documents\\Students.xlsx")

dt = pd.DataFrame(ds)







Now, Let's perform some operations related to LOC and ILOC 














Join us: https://t.me/jupyter_python

Tuesday 22 June 2021

EXPORT DATAFRAME TO EXCEL, CSV & TEXT FILE IN PANDAS || SAVE DATAFRAME IN PANDAS

EXPORT DATAFRAME TO EXCEL, CSV & TEXT FILE IN PANDAS 

Firstly, we are importing an excel sheet as a DataFrame,
 
import pandas as pd

st = pd.read_excel("C:\\Users\\mahes\\OneDrive\\Documents\\Students.xlsx")

sd = pd.DataFrame(st)

print(st)



Making some changes in the dataframe


st['Total']=st['Hindi']+st['English'] +st['Science'] +st['History']+st['Mathematics']






Now, exporting the DataFrame as Excel, CSV and Text File


sd.to_excel("C:\\Users\\mahes\\OneDrive\\Desktop\\StudentsNew.xlsx")

sd.to_csv("C:\\Users\\mahes\\OneDrive\\Desktop\\StudentsNew.csv")

sd.to_csv("C:\\Users\\mahes\\OneDrive\\Desktop\\StudentsNew.txt" ,sep = "\t")





As you can see we have created three new files.






Join us: https://t.me/jupyter_python

SORTING DATAFRAME (BY COLUMN) IN PANDAS (Part-2) - PYTHON PROGRAMMING


#SORTING DATAFRAME (BY COLUMN) IN PANDAS (Part-2) - PYTHON PROGRAMMING

Listing Two Rows


df[['Name','Total_Marks']]





df = df.drop(columns = "Total_Marks")
print(df)









Join us: https://t.me/jupyter_python 

MANIPULATING DATAFRAME IN PANDAS (ADD COLUMN , DROP COLUMN) || DATAFRAME MANIPULATIONS


import pandas as pd 
dt = pd.read_excel("C:\\Users\\mahes\\OneDrive\\Documents\\Students.xlsx")
df = pd.DataFrame(dt)
print(df)




df['Total_Marks'] = 0
print(df)




df['Total_Marks'] = df['Hindi']+df['English']
df







Join us: https://t.me/jupyter_python

SORTING DATAFRAME (BY COLUMN) IN PANDAS - PYTHON PROGRAMMING

#SORTING DATAFRAME (BY COLUMN) IN PANDAS 


#clcoding

import pandas as pd

dt = pd.read_excel("FILE_NAME")

print(dt)

df = pd.DataFrame(dt)

df.sort_values("MAXMTEMPERATURE", ascending = False)










Join us: https://t.me/jupyter_python 

Monday 21 June 2021

How do you reverse the string without take another string?



#How do you reverse the string without take another string?
#clcoding
s = 'hello'
n = -1
for x in s:
    n += 1
while n >= 0:
    print(s[n], end = '')
    n -= 1








Join us: https://t.me/jupyter_python

Sunday 20 June 2021

MATHEMATICAL FUNCTIONS ON SERIES IN PANDAS [Part 1] - PYTHON PROGRAMMING


1] Addition 

#clcoding
import pandas as pd

s1 = pd.Series([10,20,30,40,50])

s2 = pd.Series([70,80,90,100,110])

 s1.add(s2)







2] Subtraction

import pandas as pd

s1 = pd.Series([10,20,30,40,50])

s2 = pd.Series([70,80,90,100,110])

s1.subtract(s2)




 
3] Multiplication

import pandas as pd

s1 = pd.Series([10,20,30,40,50])

s2 = pd.Series([70,80,90,100,110])

s1.multiply(s2)







4] Division

import pandas as pd

s1 = pd.Series([10,20,30,40,50])

s2 = pd.Series([70,80,90,100,110])

s1.divide(s2)

        
 
                                                                      

   

Join us: https://t.me/jupyter_python

Saturday 19 June 2021

Popular Posts

Categories

AI (27) Android (24) AngularJS (1) Assembly Language (2) aws (17) Azure (7) BI (10) book (4) Books (115) C (77) C# (12) C++ (82) Course (60) Coursera (176) coursewra (1) Cybersecurity (22) data management (11) Data Science (89) Data Strucures (6) Deep Learning (9) Django (6) Downloads (3) edx (2) Engineering (14) Excel (13) Factorial (1) Finance (5) flutter (1) FPL (17) Google (19) Hadoop (3) HTML&CSS (46) IBM (25) IoT (1) IS (25) Java (92) Leet Code (4) Machine Learning (44) Meta (18) MICHIGAN (5) microsoft (3) Pandas (3) PHP (20) Projects (29) Python (746) Python Coding Challenge (200) Questions (2) R (70) React (6) Scripting (1) security (3) Selenium Webdriver (2) Software (17) SQL (40) UX Research (1) web application (8)

Followers

Person climbing a staircase. Learn Data Science from Scratch: online program with 21 courses