Search For Fun

A blog for collecting diverse useful information


  • Home

  • Tags

  • Categories

  • Archives

  • Search

python add new column to dataframe with same or different length with pandas

Posted on 2018-09-27 | Edited on 2018-07-31

description: add new column to a dataframe

initial data

1
2
3
4
5
6
a = pandas.DataFrame({'a':[1,2,3]})
# a
# a
# 0 1
# 1 2
# 2 3
1
2
3
4
5
6
b = pandas.DataFrame({'b':[2,4,6]})
# b
# b
# 0 2
# 1 4
# 2 6
1
2
3
4
5
6
7
8
c = pandas.DataFrame({'c':[1,2,3,4,5]})
# c
# c
# 0 1
# 1 2
# 2 3
# 3 4
# 4 5

concat the same length

1
2
3
4
5
pandas.concat([a,b], axis=1)
# a b
# 0 1 2
# 1 2 4
# 2 3 6

concat different length

1
2
3
4
5
6
7
pandas.concat([a,c], axis=1)
# a c
# 0 1.0 1
# 1 2.0 2
# 2 3.0 3
# 3 NaN 4
# 4 NaN 5

Microsoft Sql server installation with 1638 error

Posted on 2018-09-27 | Edited on 2018-07-18 | In sql server

description: unable to install Sql Server with exit code 1638

solution

  • exit code 1638 means a newer version of Microsoft Visual C++ has been installed
  • uninstall 2015, 2017 and others higher than 2015
  • restart the process

problem description

1
2
3
4
5
6
TITLE: Microsoft SQL Server 2017 Setup
------------------------------

The following error has occurred:

VS Shell installation has failed with exit code 1638.

more on search4fan.github.io

LSTM simplest example in python

Posted on 2018-09-27 | Edited on 2018-07-25 | In machine learning

description: simplest example for LSTM ANN in python

import packages

1
2
3
4
5
import numpy
from keras.models import Sequential
from keras.layers import Dense
from keras.layers import LSTM
import matplotlib.pyplot as plt

initial dataset

1
2
3
4
test_set = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8]
dataset = []
for i in range(1, 100):
dataset.append(i%10/10)

transform data into [current_data, next_data]

1
2
3
4
5
6
dataX, dataY = [], []
for i in range(len(dataset) - 2):
dataX.append(dataset[i])
dataY.append(dataset[i + 1])
dataX = numpy.array(dataX)
dataY = numpy.array(dataY)

reshape data

1
dataX = numpy.reshape(dataX, (dataX.shape[0], 1, 1))

create and fit the LSTM network

1
2
3
4
5
model = Sequential()
model.add(LSTM(4, input_shape=(1, 1)))
model.add(Dense(1))
model.compile(loss='mean_squared_error', optimizer='adam')
model.fit(dataX, dataY, epochs=10, batch_size=1, verbose=2)

make predictions

1
2
3
test = numpy.array(test_set)
test = numpy.reshape(test, (test.shape[0], 1, 1))
trainPredict = model.predict(test)

plot baseline and predictions

1
2
3
plt.plot(test_set)
plt.plot(trainPredict)
plt.show()

java change array into a list

Posted on 2018-09-27 | Edited on 2018-07-17 | In java

description: convert array into a list in java

convert array into list

1
ArrayList<Object> list = new ArrayList(Arrays.asList(yourArray));

more on search4fan.github.io

optimze hexo blog title for seo

Posted on 2018-09-27 | Edited on 2018-07-14 | In hexo

change index.swig file

under your-hexo-site\themes\next\layout

chang the title codes

1
{% block title %}{{ config.title }}{% endblock %}

change into

1
{% block title %}{{ config.title }} - {{ theme.description }}{% endblock %}

moreover, it can add keywords into title

1
{% block title %}{{ theme.keywords }} - {{ config.title }} - {{ theme.description }}{% endblock %}


more on http://searchfor.space

add rss feed into hexo blog - install feed plugin in hexo blog

Posted on 2018-09-27 | Edited on 2018-07-14 | In hexo

install hexo-generator-feed

1
$ npm install hexo-generator-feed --save

add following contents into _config.yml

1
2
3
4
5
6
7
8
feed:
type: atom
path: atom.xml
limit: 20
hub:
content:
content_limit: 140
content_limit_delim: ' '

more on http://searchfor.space

add google adsense into hexo blog in next theme

Posted on 2018-09-27 | Edited on 2018-07-14 | In hexo

build a new adsense template under next theme in layout/_custom

1
themes/next/layout/_custom/google_adsense.ejs

put the google adsense codes into google_adsense.ejs

1
2
3
4
5
6
7
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script>
(adsbygoogle = window.adsbygoogle || []).push({
google_ad_client: "ca-pub-5817381835091099",
enable_page_level_ads: true
});
</script>

add following codes in _layout.swig under theme folder

1
2
3
<!-- Google AdSense start -->
{% include '_custom/google_adsense.ejs' %}
<!-- Google AdSense end -->

generate web page and check source file to see the google code in there


more on searchfor.space

hexo deploy to github with ssh

Posted on 2018-09-27 | Edited on 2018-07-23 | In hexo

description: hexo deploy github pages through ssh

configuration for deploying to github with ssh

change the configuration in _config.yml under the hexo root folder

1
2
3
4
5
6
# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
type: git
repository: git@github.com:kelfan/kelfan.github.io.git
branch: master


more on search4fan.github.io

add sitemap into hexo blog

Posted on 2018-09-27 | Edited on 2018-07-14 | In hexo

install plugin for SEO sitemap

1
npm install hexo-generator-sitemap --save

optional for baidu search engine

1
npm install hexo-generator-baidu-sitemap --save

change configuration file in _config.yml

add following codes into _config.yml file and change the value of url, should be like http://yoursite.com

1
2
3
4
sitemap:
path: sitemap.xml

url: https://search4fan.github.io

optional for baidu search engine sitemap

1
2
baidusitemap:
path: baidusitemap.xml

check with public folder

after hexo g, the sitemap.xml or baidusitemap.xml should be found under public folder


more on http://searchfor.space

hexo add local search

Posted on 2018-09-27 | Edited on 2018-07-14 | In hexo

description: add a local search for hexo blog

install hexo-generator-search

run following commend under search4fan.github.io/ folder

1
npm install hexo-generator-search --save

change configuration

add following text in search4fan.github.io/_config.yml

1
2
3
search: 
path: search.xml
field: post

change theme configuration

change _config.yml under theme folder search4fan.github.io/themes/next/_config.yml

1
2
3
4
5
6
7
8
9
10
11
# Local search
# Dependencies: https://github.com/theme-next/hexo-generator-searchdb
local_search:
enable: true
# if auto, trigger search by changing input
# if manual, trigger search by pressing enter key or search button
trigger: auto
# show top n results per article, show all results by setting to -1
top_n_per_article: 1
# unescape html strings to the readable one
unescape: false


more on search4fan.github.io

1…345…7

killfun

Personal blog for collecting useful information

64 posts
14 categories
38 tags
RSS
© 2018 killfun
Powered by Hexo v3.7.1
|
Theme — NexT.Muse v6.3.0