forked from becloudready/python-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhello_python.py
More file actions
137 lines (78 loc) · 2.4 KB
/
hello_python.py
File metadata and controls
137 lines (78 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import numpy as np
import pandas as pd
import csv
import os
os.getcwd()
os.chdir('.')
os.getcwd()
#importing data from computer and other locations
newdata = pd.read_csv('sample.csv')
#newdata = pd.read_csv('E:\\Shailendra\\Personal\\TR\\sample_data\\Sample_csv_File_V1.csv')
#checking the data
#gives stats about numerical variables
checkingdata = newdata.describe()
#allows us to view first X observations
newdata.head()
#getting frequency table of a single variable
newdata['age'].value_counts()
print(newdata.columns) # prints the column names
newdata1=newdata
# reading a csv file with options
#Group by
newdata1.agg({'age':'mean'})
print(newdata1['age'].mean())
print(newdata1['age'].median())
print(newdata1['age'].std())
#Defining a function
#Example 1
def greetings(name):
"""This function greets to the person passed in as parameter"""
print("Hello, " + name + ". Good morning!")
#Calling a function
greetings("Bo")
#Example 2
def cube(num):
"""This function returns the cube of the entered number"""
if num >= 0:
return num*num*num
else:
return "negative"
cube(9)
cube(-9)
#Parameters = Information can be passed to functions as parameter.
def my_function(fname):
print(fname + " is a Data Scientist")
my_function("Bo")
my_function("Chandan")
my_function("Shailendra")
import requests
from bs4 import BeautifulSoup
url = "https://www.yelp.com/biz/after-dark-toronto"
r = requests.get(url);
# Collect all the reviews elements on the current page.
soup = BeautifulSoup(r.text, 'lxml')
#for review_block in soup('div', {'itemprop': 'review'}):
reviewer = review_block.find("meta", {"itemprop":"author"})['content']
print (reviewer)
rating = review_block.find('meta', {'itemprop': 'ratingValue'})['content']
print (rating)
feedback = review_block.find('p', {'itemprop': 'description'}).get_text();
print (feedback)
import twitter
from twitter import Twitter
from twitter import OAuth
consumer_key = ""
consumer_secret = ""
access_token = ""
access_token_secret = ""
oauth= OAuth(access_token,access_token_secret,consumer_key,consumer_secret)
api= Twitter(auth=oauth)
import pandas as pd
from textblob import TextBlob
search_results = api.search.tweets(q="trump", count=2)
#print (search_results)
data = []
for tweet in search_results['statuses']:
print (tweet['text'])
print(TextBlob(tweet['text']))
print(TextBlob(tweet['text']).sentiment.polarity)