小编nil*_*ore的帖子

VS Code:ModuleNotFoundError:没有名为“pandas”的模块

pandas尝试在 VS Code 中导入

import pandas
Run Code Online (Sandbox Code Playgroud)

并得到了

Traceback (most recent call last):
  File "c:\Users\xxxx\hello\sqltest.py", line 2, in <module>
    import pandas
ModuleNotFoundError: No module named 'pandas'
Run Code Online (Sandbox Code Playgroud)

pandas尝试安装

pip install pandas

pip3 install pandas

python -m pip install pandas
Run Code Online (Sandbox Code Playgroud)

分别返回的

(.venv) PS C:\Users\xxxx\hello> pip3 install pandas

Requirement already satisfied: pandas in c:\users\xxxx\hello\.venv\lib\site-packages (1.1.0)
Requirement already satisfied: pytz>=2017.2 in c:\users\xxxx\hello\.venv\lib\site-packages (from pandas) (2020.1)
Requirement already satisfied: numpy>=1.15.4 in c:\users\xxxx\hello\.venv\lib\site-packages (from pandas) (1.19.1)
Requirement already satisfied: python-dateutil>=2.7.3 in c:\users\xxxx\hello\.venv\lib\site-packages (from pandas) (2.8.1) …
Run Code Online (Sandbox Code Playgroud)

python visual-studio-code

19
推荐指数
4
解决办法
13万
查看次数

将 VS Code Jupyter Notebook 中的输出折叠到可滚动窗口中

有没有办法在 VS Code Jupyter Notebook 的可滚动窗口中显示输出,例如非常长的数据帧?

我知道按字母“o”可以折叠所有输出。但拥有可滚动窗口仍然更好,因为它允许您在引用其他窗口的同时检查输出。

我也检查了此链接,但无法使其工作。

python dataframe visual-studio-code jupyter-notebook

12
推荐指数
2
解决办法
2万
查看次数

ValueError: Mime 类型渲染需要 nbformat&gt;=4.2.0 但未安装

我试图在 Visual Studio Code 中打印一个情节图并发现了这个错误:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-40-e07b5feb5ded> in <module>
     30 
     31 fig.update_layout(height=nrows*500)
---> 32 fig.show()

C:\Python38\lib\site-packages\plotly\basedatatypes.py in show(self, *args, **kwargs)
   3147         import plotly.io as pio
   3148 
-> 3149         return pio.show(self, *args, **kwargs)
   3150 
   3151     def to_json(self, *args, **kwargs):

C:\Python38\lib\site-packages\plotly\io\_renderers.py in show(fig, renderer, validate, **kwargs)
    383 
    384         if not nbformat or LooseVersion(nbformat.__version__) < LooseVersion("4.2.0"):
--> 385             raise ValueError(
    386                 "Mime type rendering requires nbformat>=4.2.0 but it is not installed"
    387             )

ValueError: Mime type rendering …
Run Code Online (Sandbox Code Playgroud)

python pandas plotly nbformat

8
推荐指数
3
解决办法
7464
查看次数

AttributeError:“Timedelta”对象没有属性“dt”

我有一个df

    id  timestamp                       data  group Date
27001   27242   2020-01-01 09:07:21.277 19.5    1   2020-01-01
27002   27243   2020-01-01 09:07:21.377 19.0    1   2020-01-01
27581   27822   2020-01-02 07:53:05.173 19.5    1   2020-01-02
27582   27823   2020-01-02 07:53:05.273 20.0    1   2020-01-02
27647   27888   2020-01-02 10:01:46.380 20.5    1   2020-01-02
...
Run Code Online (Sandbox Code Playgroud)

我想计算第 1 行和第 2 行之间的时间差(以秒为单位)。我可以用

df['timediff'] = (df['timestamp'].shift(-1) - df['timestamp']).dt.total_seconds()
Run Code Online (Sandbox Code Playgroud)

但是,当我放大仅查看 2 行时,即。row1和row0,代码:

difference = (df.loc[0, 'timestamp'] - df.loc[1, 'timestamp']).dt.total_seconds()
Run Code Online (Sandbox Code Playgroud)

它返回错误

AttributeError:“Timedelta”对象没有属性“dt”

为什么会发生这种情况?

python datetime numpy pandas

6
推荐指数
2
解决办法
2万
查看次数

在Python中打开Excel文件:XLRDError: Excel xlsx file; 不支持

我想在 Python 中打开 Excel 文件,使用:

import xlrd

loc = (r"C:\Users\my_path\my_file.xlsx")

wb = xlrd.open_workbook(loc)
sheet = wb.sheet_by_index(0)
sheet.cell_value(0, 0)
Run Code Online (Sandbox Code Playgroud)

它捕获了错误:

---------------------------------------------------------------------------
XLRDError                                 Traceback (most recent call last)
<ipython-input-70-b399ced4986e> in <module>
      4 loc = (r"C:\Users\my_path\my_file.xlsx")
      5 
----> 6 wb = xlrd.open_workbook(loc)
      7 sheet = wb.sheet_by_index(0)
      8 sheet.cell_value(0, 0)

C:\Python38\lib\site-packages\xlrd\__init__.py in open_workbook(filename, logfile, verbosity, use_mmap, file_contents, encoding_override, formatting_info, on_demand, ragged_rows, ignore_workbook_corruption)
    168     # files that xlrd can parse don't start with the expected signature.
    169     if file_format and file_format != 'xls':
--> 170 …
Run Code Online (Sandbox Code Playgroud)

python excel pandas

6
推荐指数
2
解决办法
3万
查看次数

OSError: SavedModel 文件不存在于:/content\model\2016/{saved_model.pbtxt|saved_model.pb}

我运行了代码

export_path=os.getcwd()+'\\model\\'+'2016'

with tf.Session(graph=tf.Graph()) as sess:
    tf.saved_model.loader.load(sess, ["myTag"], export_path)          
    graph = tf.get_default_graph()
#    print(graph.get_operations())
    input = graph.get_tensor_by_name('input:0')
    output = graph.get_tensor_by_name('output:0')    
#     print(sess.run(output,
#                feed_dict={input: [test_data[1]]}))
    tf.train.write_graph(freeze_session(sess), export_path, "my_model.pb", as_text=False)
Run Code Online (Sandbox Code Playgroud)

并导致以下错误

OSError                                   Traceback (most recent call last)
<ipython-input-44-b154e11ca364> in <module>()
      3 
      4 with tf.Session(graph=tf.Graph()) as sess:
----> 5     tf.saved_model.loader.load(sess, ["myTag"], export_path)          
      6     graph = tf.get_default_graph()
      7 #    print(graph.get_operations())

3 frames
/usr/local/lib/python3.6/dist-packages/tensorflow/python/saved_model/loader_impl.py in parse_saved_model(export_dir)
     81                   (export_dir,
     82                    constants.SAVED_MODEL_FILENAME_PBTXT,
---> 83                    constants.SAVED_MODEL_FILENAME_PB))
     84 
     85 

OSError: SavedModel file does not exist at: /content\model\2016/{saved_model.pbtxt|saved_model.pb}
Run Code Online (Sandbox Code Playgroud)

它以前在Windows系统中运行,现在在IOS中运行。我不确定是不是因为这个。任何帮助表示赞赏。谢谢你。

python tensorflow google-colaboratory

5
推荐指数
1
解决办法
9822
查看次数

如何恢复 Google Colab 中未保存的代码

我读过一些大型 csv 文件,这些文件占用了大量 RAM,我注意到它Colab崩溃了一次,我不得不重新运行所有代码。Colab我在睡觉前保存了文件,但是当我醒来时,我前一天添加的代码全部消失了。没有Colab保存我的代码?有没有办法恢复未保存的代码?

python google-colaboratory

5
推荐指数
1
解决办法
1万
查看次数

使用 scikit-learn 对具有多重输入的 Keras 模型进行交叉验证

我想将 K-Fold 交叉验证应用于我的神经网络模型,如下所示:

from sklearn.model_selection import StratifiedKFold 
from numpy import *
from keras.wrappers.scikit_learn import KerasClassifier
from sklearn.model_selection import cross_val_score
import numpy

X = df.iloc[:,0:10165]  
X = X.to_numpy()                      
X = X.reshape([X.shape[0], X.shape[1],1]) 
X_train_1 = X[:,0:10080,:]                     
X_train_2 = X[:,10080:10165,:].reshape(921,85)      
Y = df.iloc[:,10168:10170]
Y = Y.to_numpy()

def my_model():

    inputs_1 = keras.Input(shape=(10080,1))
    layer1 = Conv1D(64,14)(inputs_1)
    layer2 = layers.MaxPool1D(5)(layer1)
    layer3 = Conv1D(64, 14)(layer2)       
    layer4 = layers.GlobalMaxPooling1D()(layer3)

    inputs_2 = keras.Input(shape=(85,))
    layer5 = layers.concatenate([layer4, inputs_2])
    layer6 = Dense(128, activation='relu')(layer5)
    layer7 = Dense(2, activation='softmax')(layer6)

    model_2 = keras.models.Model(inputs = …
Run Code Online (Sandbox Code Playgroud)

python machine-learning neural-network scikit-learn keras

5
推荐指数
1
解决办法
753
查看次数

numpy.fft.fft 和 numpy.fft.fftfreq 有什么区别

我正在分析时间序列数据,并希望提取 5 个主要频率分量并将其用作训练机器学习模型的特征。我的数据集是921 x 10080. 每行是一个时间序列,总共有 921 个。

在探索可能的方法时,我遇到了各种函数,包括numpy.fft.fft,numpy.fft.fftfreqDFT... 我的问题是,这些函数对数据集有什么作用,这些函数之间有什么区别?

对于Numpy.fft.fft,Numpy 文档状态:

Compute the one-dimensional discrete Fourier Transform.

This function computes the one-dimensional n-point discrete Fourier Transform (DFT) with the efficient Fast Fourier Transform (FFT) algorithm [CT].
Run Code Online (Sandbox Code Playgroud)

而对于numpy.fft.fftfreq

numpy.fft.fftfreq(n, d=1.0)
Return the Discrete Fourier Transform sample frequencies.

The returned float array f contains the frequency bin centers in cycles per unit of the sample spacing (with zero at …
Run Code Online (Sandbox Code Playgroud)

python numpy fft time-series

5
推荐指数
2
解决办法
1万
查看次数

更改 VSC Jupyter Notebook 输出的 mimetype

我想将 VSC 中的输出格式从 更改htmlplain. 我注意到我可以对单个单元格执行此操作,如下所示,但我想知道是否可以更改整个文件的 settings.json 。我正在使用 Jupyter 笔记本。

在此输入图像描述

visual-studio-code jupyter-notebook

4
推荐指数
1
解决办法
3509
查看次数