我有数据框:
import pandas as pd
data = [[101, 1, 2, 10, 3, 2, 3, 1], [5,5, 5, 5, 5, 5, 5, 5], [30, 3, 7, 14, 10, 7, 10, 2], [11, 2, 6, 15, 20, 6, 20, 11]]
df = pd.DataFrame(data, columns = ['xen', 'sim', 'tab', 'sim', 'simm', 'box', 'simm', 'res'])
Run Code Online (Sandbox Code Playgroud)
看起来像:
| xen | sim | tab | sim | simm | box | simm | res |
|------:|------:|------:|------:|-------:|------:|-------:|------:|
| 101 | 1 | 2 | 10 | 3 …Run Code Online (Sandbox Code Playgroud) 完成后pip install pyaudio,它开始收集包,但突然显示此错误。希望以下内容可以解释正在发生的事情:
Collecting pyaudio
Using cached PyAudio-0.2.11.tar.gz (37 kB)
Installing collected packages: pyaudio
Running setup.py install for pyaudio ... error
ERROR: Command errored out with exit status 1:
command: 'C:\Users\mayank\AppData\Local\Programs\Python\Python38-32\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\mayank\\AppData\\Local\\Temp\\pip-install-b1kw0ltr\\pyaudio\\setup.py'"'"'; __file__='"'"'C:\\Users\\mayank\\AppData\\Local\\Temp\\pip-install-b1kw0ltr\\pyaudio\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\mayank\AppData\Local\Temp\pip-record-s8qn1fa4\install-record.txt' --single-version-externally-managed --compile --install-headers 'C:\Users\mayank\AppData\Local\Programs\Python\Python38-32\Include\pyaudio'
cwd: C:\Users\mayank\AppData\Local\Temp\pip-install-b1kw0ltr\pyaudio\
Run Code Online (Sandbox Code Playgroud)
完整输出(15 行):
running install
running build
running build_py
creating build
creating build\lib.win32-3.8
copying src\pyaudio.py -> build\lib.win32-3.8
running build_ext
building '_portaudio' extension
creating build\temp.win32-3.8 …Run Code Online (Sandbox Code Playgroud) 作为数据分析练习的一部分,我正在将 excel 表读取到 Pandas 数据框中。
df = pd.ExcelFile('file.xlsx').parse(0)
nullcounts = df.isnull().sum().to_frame('null_records')
Run Code Online (Sandbox Code Playgroud)
为我的数据帧中的每个系列生成一个带有空计数的漂亮帧。但是如果字符串 'NA' 出现在一行数据中,我不希望isnull操作返回True。
有没有一种简单的方法可以在不为特定列/数据帧硬编码规则的情况下做到这一点?
编辑:看来,被读入大熊猫当我的源数据在NAS被忽略,因为当我加载数据,并比较直观地看到我NaN在Excel中,那里有NA。
I have a question, how does
pow(num, power, mod)
Run Code Online (Sandbox Code Playgroud)
work so much faster than
(num**power)%mod
Run Code Online (Sandbox Code Playgroud)
On large numbers the second is unusable, so i'm wondering how pow() works. How does it work to be so much faster, what is the underpinning of how it works with mod to calculate an answer so much faster than
(num**power)%mod.
Run Code Online (Sandbox Code Playgroud)
(num * * power)%mod is unusable with larger numbers
so i'm wondering what trick pow() uses to calculate the answer so quickly? Does it …
这个问题让我很困惑。可能问题出在代码上,希望你看看
with open(training_images_labels_path,'r') as file:
lines = file.readlines()
Run Code Online (Sandbox Code Playgroud)
他说文件不存在
FileNotFoundError: [Errno 2] No such file or directory: '\\Desktop\\project\\data\\generated\\training_images_labels.txt'
Run Code Online (Sandbox Code Playgroud)
虽然文件存在
我需要解决方案
我正在尝试编写一个循环来检查列表中列表中的某个数字是否未出现。例如:如果我有列表
[[1,'O', 3], [4, 5, 6], [7, 8, 'X']]
Run Code Online (Sandbox Code Playgroud)
我想编写一个循环来检查数字是否2出现在其中一个列表中,如果没有,则要求您选择一个新数字。到目前为止,我坚持这一点:
move = 2
for i in range(3):
for j in range(3):
if move not in board[i][j]:
move = int(input("Number already taken. Pick another"))
Run Code Online (Sandbox Code Playgroud)
但它不起作用。这似乎是一个相当简单的检查,但我不知道为什么它不会运行。有没有人有更好的建议如何检查给定数字的这些列表?
干杯
C/C++ 因在许多情况下比 python 更快而闻名。我朝这个方向做了一个测试。
我有一个包含 2200 行的大型(美化的)JSON 文件。测试包括读取文件、反序列化内存中的数据(我使用字典作为数据结构)并显示内容。
我使用内置json库在 python 中执行测试,并使用外部nlohmann JSON 库在 C++ 中执行测试。
运行几次后,我震惊地发现 C++ 需要 0.01 秒,而 Python 3 大约需要 0.001 秒,几乎快了 10 倍!
我在文档中进行了搜索,但没有找到有关编写json库时使用的内容的信息。
C++:
#include <iostream>
#include <string.h>
#include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/ptree.hpp>
#include "nlohmann/json.hpp"
using namespace std;
using json = nlohmann::json;
namespace pt = boost::property_tree;
#include <ctime>
int main()
{
ifstream input;
input.open("input.json");
json json_data;
input >> json_data;
cout << json_data << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
和Python:
import json
from …Run Code Online (Sandbox Code Playgroud) 我在我的 Linux 系统上安装了 anaconda,同时安装它要求conda config --set auto_activate_base False or True设置。如果我设置conda config --set auto_activate_base True它(base) vijay@vijay-HP-Notebook:~$在终端用户名之前添加 base() ,如果设置conda config --set auto_activate_base False它删除 base()。这有什么实际意义。我应该将其设置为True或False。
我是 Python 的初学者,不了解以下内容:我定义了一个类和一个列表。当我想在附加后打印列表时,我没有得到字符串,尽管我有一个方法应该返回一个字符串,对吗?我不明白这里有什么问题.. :/ 我希望结果是 [14,12] ... 如果有人知道我做错了什么,请告诉我:/
class av:
def __init__(self, num):
self.num = num
def __str__(self,num):
self.num = num
return str(self.num)
lst = []
lst.append(av(14))
lst.append(av(12))
print(lst)
Run Code Online (Sandbox Code Playgroud)
结果:
[<__main__.av object at 0x102503dd0>, <__main__.av object at 0x102505d90>]
Run Code Online (Sandbox Code Playgroud) 我正在使用 openpyxl 模块,但现在发现它不支持 csv 格式。那么,如何区分传入的文件是.xlsx还是.csv格式