Sign in

API simple_salesforce allows us to access Salesforce. And we can use it to post a message to Salesforce’s Chatter.

from simple_salesforce import Salesforce
import requests
import pandas as pd
import csv
import requests
from io import StringIO
import getpass
import json
import datetime

Then access to Salesforce is provided by username, password, and security token. (We can access Salesforce using username, password, and organizationId as well.)

sf0=Salesforce(username=USERNAME, password=PASSWORD, security_token=SECURITY_TOKEN)

Then, we use restful method and json to post a message to Chatter.

message_a="Awesome! A message was posted at " +'%Y-%m-%d %H:%M:%S')
body0 = { "body":
{"messageSegments": [
{"type": "Text", "text": message_a},
{"type": "Mention", "id": user_id}
"feedElementType": "FeedItem", "subjectId": "me"
zz_rest0=sf0.restful(r'chatter/feed-elements/', method='POST', data=json.dumps(body0))

Here user_id is the id of the user whom we send a message.

In python pandas, axis=0 means that a dataframe (table) is processed in the way that a row is a building block. For instance, you use pandas.concat to stack rows:

An easy code to carry out LDA

First we import the following libraries:

import MeCab
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.decomposition import LatentDirichletAllocation

Here, MeCab is a library to tokenize Japanese texts. Then, using CountVectorizer, we make a table to count the number of appearance for each word.

cnt_vec = CountVectorizer()
#print('dfw.shape=', dfw.shape)
mat1 = cnt_vec.fit_transform( df_tot['sent'] )
df1=pd.DataFrame( mat1.toarray(), columns=cnt_vec.get_feature_names() )lda1 = LatentDirichletAllocation(n_components = num_topics, random_state = 5, learning_method='online')
print(lda1.exp_dirichlet_component_.shape, mat1.shape)
df_word_topic=pd.DataFrame( lda1.exp_dirichlet_component_, columns=cnt_vec.get_feature_names() ).transpose().reset_index()
list_topics=['topic_' + str(jv) for jv in np.arange(0, …

Suppose a neural network consists of 3 layers: input, hidden and output layers. Each layers are linked to each other via a neuron-like object, and the information propagates from the input layer to the output.

Each layer has parameters, and in this case parameters are V, W, b, c. What the neural network learns means that the parameters are optimized such that the error is minimized. The optimization is done through iteration. This is the main process of deep learning.

Bag-of-words (BoW) is a simple way to represent a collection of documents under the assumption that each document is represented by a distribution of words. In the model, the number of times that words appear in each document of a collection is counted. BoW is often used in document classification.

And its implementation is easy; you only use scikit-learn and nltk (provided the word set is in English.) First, you use nltk to have:

Secondly, you use scikit-learn to have:

Suppose you use Tableau on macOS & try to connect to a data source (eg .xlsx file). And if you get an error message like

An error occurred while communicating with Tableau Data Extract
Bad Connection: Tableau could not connect to the data source.
Error Code: ******
Could not start Hyper: Failed to start a new Hyper instance.
Caused by:
The Hyper server process exited during startup with exit code: 1
d.log”, 514): Operation not permitted

then you can solve the problem in a simple way (although the solution is not permanent).

The solution is to start Tableau from a terminal: for example if you use Tableau Public, you type:

/Applications/Tableau\\ Public

Then you can connect to a data source.

When you start to use nltk module, you need to download and install the data relating to the module. For example

>>> import nltk

Then, if you have the error messages like

[nltk_data] Error loading punkt: <urlopen error [SSL:
[nltk_data] CERTIFICATE_VERIFY_FAILED] certificate verify failed:
[nltk_data] unable to get local issuer certificate

you need to go to this website and manually download models. In this case, you need to unzip the downloaded .zip files, and you move the extracted files into directory /usr/local/share/nltk_data/tokenizers/ , provided that you use MacOS.

Similarly, if you run

>>> from import *


From version 1.1.0 two dataframes are easily compared in terms of their elements. Now we have dataframes df_a (left) and df_b (right):



gives us False, which means that the two tables are not equal. Aside: if you want to check if the columns of the two tables are equal, then you could write:


And the return value is True in this case. (Actually, this might be a useful expression, and available for many occasions.)

Then we type:, keep_equal=True)
print(‘df_c=\n’, df_c)

This shows the difference for the tables

Actually, when I posted the previous article Testing nquad, I was told (by Medium) to change my Medium URL.



T Miyamoto

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store