This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Takes a list of status/twitter objects, extracts the text, | |
# cleans the text, calculates word frequencies and generates | |
# a word cloud. | |
generateWordCloud <- function(tweets){ | |
#Get the text from the status/twitter object | |
tweets_list <- sapply(tweets, function(x) x$getText()) | |
#Remove any weird symbols from the text | |
tweets_list <- str_replace_all(tweets_list, "[^[:graph:]]", " ") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Install a package and load it. | |
installRequiredPackages <- function(pkg){ | |
new.pkg <- pkg[!(pkg %in% installed.packages()[,"Package"])] | |
if (length(new.pkg)) | |
install.packages(new.pkg, dependencies = TRUE) | |
sapply(pkg, require, character.only = TRUE) | |
} | |
libs <- c("readr", "dplyr", "tidyr", "ggplot2", | |
"magrittr", "markdown", "knitr", "Hmisc", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
df <- data.frame( | |
a = rnorm(10), | |
b = rnorm(10), | |
c = rnorm(10), | |
d = rnorm(10) | |
) | |
# Replace the 1:ncol(df) sequence | |
for (i in seq_along(df)) { | |
print(median(df[[i]])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Define lists2dict() | |
def lists2dict(list1, list2): | |
"""Return a dictionary where list1 provides | |
the keys and list2 provides the values.""" | |
# Zip lists: zipped_lists | |
zipped_lists = zip(list1, list2) | |
# Create a dictionary: rs_dict | |
rs_dict = dict(zipped_lists) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Import the pandas package | |
import pandas as pd | |
# Turn list of lists into list of dicts: list_of_dicts | |
# https://gist.github.com/shravan-kuchkula/6ca3054d5ec0549e1759d739b3d47513 | |
list_of_dicts = [lists2dict(feature_names, sublist) for sublist in row_lists] | |
# Turn list of dicts into a dataframe: df | |
df = pd.DataFrame(list_of_dicts) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<TLSales xmlns="http://tlsales.com/namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://tlsales.com/namespace /tmp/msds7330/customer.xsd"> | |
<Address> | |
<Name>Addr1</Name> | |
<Street>123 Main St.</Street> | |
<City>Seattle</City> | |
</Address> | |
<Customer OneTime="true" Regular="false" Senior="false" Discount="5"> | |
<First>John Q.</First> | |
<Last>Public</Last> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# To insert the data in the people collection use 'insertOne.py' that I have given earlier | |
# Display the contents of the people collection | |
> db.people.find() | |
{ "_id" : ObjectId("59a36310fc2b2b3d843af1b6"), "name" : "Smith", "age" : 30, "profession" : "hacker" } | |
{ "_id" : ObjectId("59a36310fc2b2b3d843af1b7"), "name" : "Jones", "age" : 35, "profession" : "baker" } | |
{ "_id" : ObjectId("59a36310fc2b2b3d843af1b8"), "name" : "Alice" } | |
{ "_id" : ObjectId("59a36310fc2b2b3d843af1b9"), "name" : "Bob" } | |
{ "_id" : ObjectId("59a36310fc2b2b3d843af1ba"), "name" : "Charlie" } | |
{ "_id" : ObjectId("59a36310fc2b2b3d843af1bb"), "name" : "Dave" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pymongo | |
connection = pymongo.MongoClient("mongodb://localhost") | |
db = connection.school | |
people = db.people | |
people.drop() | |
def insert(peopleList): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
files = os.listdir(os.getcwd()) | |
[os.replace(file, file.replace(" ", "_")) for file in files] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Conda is a powerful package manager and environment manager that you use with command line commands at the Anaconda Prompt for Windows, or in a Terminal window for macOS or Linux. | |
Common Commands: | |
a. To see a list of all your environments, type: | |
conda info --envs | |
$conda info --envs | |
# conda environments: | |
# | |
base * /Users/Shravan/anaconda3 |
OlderNewer