我想将 pandas cut 函数应用于包含 NaN 的系列。所需的行为是将非 NaN 元素分桶并为 NaN 元素返回 NaN。
import pandas as pd
numbers_with_nan = pd.Series([3,1,2,pd.NaT,3])
numbers_without_nan = numbers_with_nan.dropna()
Run Code Online (Sandbox Code Playgroud)
切割适用于没有 NaN 的系列:
pd.cut(numbers_without_nan, bins=[1,2,3], include_lowest=True)
0 (2.0, 3.0]
1 (0.999, 2.0]
2 (0.999, 2.0]
4 (2.0, 3.0]
Run Code Online (Sandbox Code Playgroud)
当我剪切包含 NaN 的系列时,元素 3 正确返回为 NaN,但最后一个元素分配了错误的 bin:
pd.cut(numbers_with_nan, bins=[1,2,3], include_lowest=True)
0 (2.0, 3.0]
1 (0.999, 2.0]
2 (0.999, 2.0]
3 NaN
4 (0.999, 2.0]
Run Code Online (Sandbox Code Playgroud)
我怎样才能得到以下输出?
0 (2.0, 3.0]
1 (0.999, 2.0]
2 (0.999, 2.0]
3 NaN
4 (2.0, 3.0]
Run Code Online (Sandbox Code Playgroud) 我有以下代码:
这是我的代码:
print (start_timestamp)
start_timestamp_no_iso = datetime.strptime(start_timestamp, "%Y-%m-%dT%H:%M:%S.%f")
Run Code Online (Sandbox Code Playgroud)
这是我得到的:
INFO - 2018-11-20T14:44:03.452131
INFO - Traceback (most recent call last):
INFO - File "/home/ubuntu/script.py", line 84, in <module>
INFO - start_timestamp_no_iso = datetime.strptime(start_timestamp, "%Y-%m-%dT%H:%M:%S.%f")
INFO - File "/usr/lib/python3.6/_strptime.py", line 565, in _strptime_datetime
INFO - tt, fraction = _strptime(data_string, format)
INFO - File "/usr/lib/python3.6/_strptime.py", line 365, in _strptime
INFO - data_string[found.end():])
INFO - ValueError: unconverted data remains:
INFO - Command exited with return code 1
Run Code Online (Sandbox Code Playgroud)
我了解这意味着什么,但我不明白为什么会发生。我只是将时间戳从iso格式转换为non iso。问题是什么?
正如您可能注意到的,我对 python 和声音处理非常陌生。我(希望)使用 python 以及 logfbank 和 mfcc 函数从波形文件中提取 FFT 数据。(logfbank 似乎提供了最有希望的数据,mfcc 输出对我来说看起来有点奇怪)。
在我的程序中,我想更改 logfbank/mfcc 数据,然后从中创建波形数据(并将它们写入文件中)。我确实没有找到任何有关从 FFT 数据创建波形数据的过程的信息。你们中有人知道如何解决这个问题吗?我将非常感激:)
到目前为止,这是我的代码:
from scipy.io import wavfile
import numpy as np
from python_speech_features import mfcc, logfbank
rate, signal = wavfile.read('orig.wav')
fbank = logfbank(signal, rate, nfilt=100, nfft=1400).T
mfcc = mfcc(signal, rate, numcep=13, nfilt=26, nfft=1103).T
#magic data processing of fbank or mfcc here
#creating wave data and writing it back to a .wav file here
Run Code Online (Sandbox Code Playgroud) 请分享如何在Redhat Linux上安装pip的步骤。我已经尝试了以下命令。
sudo yum install python-pip
yum install python-devel
apt-get install python-pip
Run Code Online (Sandbox Code Playgroud)
问候,苏索万
我需要从像这样的词典列表中生成2个列表{'key1': 'val1', 'key2': 'val2', ...}.在功能风格(但2通):
list_key1 = map(itemgetter('key1'), any_list)
list_key2 = map(itemgetter('key2'), any_list)
Run Code Online (Sandbox Code Playgroud)
通常的风格(1通):
list_key1, list_key2 = [], []
for i in any_list:
list_key1.append(i['key1'])
list_key2.append(i['key2'])
Run Code Online (Sandbox Code Playgroud)
有没有办法以功能风格和1次通过?
我尝试在 pycharm 中安装 pyaudio,然后
我收到这个错误
Run Code Online (Sandbox Code Playgroud)error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\cl.exe' failed with exit status 2
我使用了pip install pyaudio命令。
复制评论:
PyAudio?0.2.11?cp37?cp37m?win_amd64.whl 尝试使用此命令安装它
pip install PyAudio?0.2.11?cp37?cp37m?win_amd64
Run Code Online (Sandbox Code Playgroud)但它不起作用并出现此错误
ERROR: Could not find a version that satisfies the requirement PyAudio-0.2.11-cp37-cp37m-win_amd64 (from versions: none)
ERROR: No matching distribution found for PyAudio-0.2.11-cp37-cp37m-win_amd64
Run Code Online (Sandbox Code Playgroud) 我有一个键列表和值列表。
['OpenInterest_x', 'Change in Open Interest x', 'LTP_x', 'NetChange_x', 'Volume_x', 'BidQty_x', 'BidPrice_x', 'OfferPrice_x', 'OfferQty_x', 'Strike Price', 'BidQty', 'BidPrice', 'OfferPrice', 'OfferQty', 'Volume', 'NetChange', 'LTP', 'OpenInterest', 'Change in Open Interest'
]
[
['150', '150', '1,070.00', '-928.90', '2', '450', '1,097.20', '1,314.15', '1,875', '4500.00', '375', '3.20', '10.25', '75', '-', '-', '-', '-', '-'],
['-', '-', '-', '-', '-', '150', '1,001.90', '1,056.15', '150', '4600.00', '75', '7.00', '17.80', '150', '4', '-7.55', '10.00', '1,350', '300']
]
Run Code Online (Sandbox Code Playgroud)
我有兴趣从两个字典中创建一个。请注意订购也很重要。这是我的预期输出。
{
{'OpenInterest_x': '150', ...},
{'OpenInterest_x': '-', ...},
}
Run Code Online (Sandbox Code Playgroud)
我无法在此处使用zip,因为它将为第一个键分配完整的第一列表。做这个的最好方式是什么?
python ×7
list ×2
pip ×2
python-2.7 ×2
dictionary ×1
fft ×1
linux ×1
mfcc ×1
nan ×1
pandas ×1
pyaudio ×1
spectrogram ×1
time ×1
windows ×1
x86-64 ×1