日常问题解决汇总

日常操作时遇到各种报错或新想法,所遇问题以及搜索到的解决方案参考来源大汇总(持续更新)

Python数据科学库

1. URLError:
# 原代码
import seaborn as sns
planets = sns.load_dataset('planets')

解决:从github下载数据集,用pandas调用

  • mwaskom/seaborn-data - GitHub
import pandas as pd
planets = pd.read_csv('./seaborn-data-master/planets.csv')
2. Keyerror: ‘Date’
  • Keyerror ‘Date’ when using pandas datareader - Stackoverflow

I received the ‘Keyerror ‘Date’ when using pandas datareader’ error and found two errors in my script that fixed the issue:

  1. The name of the entity was incorrect, for example using ‘APPL’ instead of ‘AAPL’.
  2. There was no data for the date parameters I was using.
# 解决代码
# Use 'BTC-USD' stock/security value
import pandas as pd
import pandas_datareader.data as web
import datetime as dt

start = dt.datetime(2017, 1, 1)
end = dt.datetime(2019, 11, 30)

df = web.DataReader('BTC-USD', 'yahoo', start, end)
df.to_csv('BTC.csv')
print(df.head())
  • 如不确定数据集起始时间也可以设置时间,如下
yhoo = data.DataReader('BTC-USD', data_source='yahoo')
yhoo.head()

日常问题解决汇总_第1张图片

yhoo.tail()

日常问题解决汇总_第2张图片

  • 可以看出数据集起始时间是2015年至2020年
3. NotImplementedError: data_source=None is not implemented
# 原代码
from pandas_datareader impoart data
goog = data.DataReader('GOOG', start='2004', end='2016')
goog.head()
  • Issue when running DataReader - pandas-datareader issue - GitHub

As of v0.7.0 Google finance and Morningstar have been immediately deprecated due to large changes in their API and no stable replacement.

4. TypeError: ‘float’ object cannot be interpreted as an integer
# 原代码
import numpy as np
rng = np.random.RandomState(42)
rng.rand(1E6)

解决方案:

# [1E6]是float类型,所以先转换为int
rng.rand(int(1E6))
  • Why doesn’t scientific notation work in Numpy - Stackoverflow

终端

1. pip install 下载库时中途报错,切换网络重试
  • 诡异的错误:OpenSSL.SSL.Error: [(‘SSL routines’, ‘ssl3_get_record’, ‘decryption failed or bad record mac’)
2. 安装homebrew时显示 connection refuse
  • Homebrew installation on Mac OS X Failed to connect to raw.githubusercontent.com port 443

解决方案:

  1. 将网址打开并保存至本地:https://raw.githubusercontent.com/Homebrew/install/master/install.sh
  2. 打开终端,运行:/bin/bash path-to/install.sh (path-to是网址保存的绝对路径)
  1. open the home page of brew https://brew.sh/
  2. copy the URL from the install cmd and open it on your browser https://raw.githubusercontent.com/Homebrew/install/master/install.sh
  3. right-click and save it to your computer
  4. open a terminal and run it with: /bin/bash path-to/install.sh

Markdown

1. 正文序号下继续分级,多空几个空格可以实现
  • 研究了一个markdown做多级编号

软件安装及配置

1. 设置Mac终端、pip、Anaconda、PyCharm共用一套环境
  • 设置Mac终端、pip、Anaconda、PyCharm共用一套环境
2.

你可能感兴趣的:(Python3)