我使用 python yfinance yahoo API 进行股票数据检索。现在我得到的是挂钩比率,这是公司价格与其增长和收益相关的指标。我从这里下载了一个 csv: https: //www.nasdaq.com/market-activity/stocks/screener。它正好有 8000 只股票。
我所做的是获取符号列表,并迭代它以访问雅虎股票。然后我使用ticker.info 方法返回一个字典。我通过 8000 个符号重复这个过程。它以每分钟 6 个符号的速度运行,这是不可行的。是否有使用其他 API 或其他结构的更快方法?我不关心 API,只要我能获得增长、收益、每股收益等基本信息即可。
这是代码:
import pandas as pd
import yfinance as yf
data = pd.read_csv("data/stock_list.csv")
symbols = data['Symbol']
for symbol in symbols:
stock = yf.Ticker(symbol)
try:
if stock.info['pegRatio']:
print(stock.info['shortName'] + " : " + str(stock.info['pegRatio']))
except KeyError:
pass
Run Code Online (Sandbox Code Playgroud) 我正在做一个数据分析项目,其中处理的数据非常大。我最初用纯 python 做了所有事情,但现在尝试用 numpy 和 pandas 来做。然而,我似乎遇到了障碍,因为不可能在 numpy 中处理大于 64 位的整数(如果我在 numpy 中使用 python 整数,它们的最大值为 9223372036854775807)。我是否完全抛弃 numpy 和 pandas 还是有办法将它们与 python 风格的任意大整数一起使用?我对性能受到影响没关系。
尝试实现研究论文: https://ieeexplore.ieee.org/document/9479786/ 使用架构训练单调网络:
class Model(nn.Module):
def __init__(self, q, s):
self.layer_s_list = [nn.Linear(5, s) for _ in range(q)]
self.inv_w, self.inv_b = self.get_layer_weights()
def forward(self, x):
# print(inv_w[0].shape, inv_b[0].shape)
output_lst = []
for layer in self.layer_s_list:
v, id = torch.max(layer(x), 1)
output_lst.append(v.detach().numpy())
output_lst = np.array(output_lst)
output_lst = torch.from_numpy(output_lst)
out, _ = torch.min(output_lst, 0)
allo_out = F.softmax(out)
pay_out = nn.ReLU(inplace = True)(out)
inv_out_lst = []
for q_idx in range(len(self.inv_w)):
# print(inv_w[q_idx].shape, pay_out.shape, inv_b[q_idx].shape)
y, _ = torch.min(torch.linalg.pinv(self.inv_w[q_idx]) * (pay_out - self.inv_b[q_idx]), 0)
inv_out_lst.append(y.detach().numpy()) …Run Code Online (Sandbox Code Playgroud) machine-learning neural-network deep-learning data-science federated-learning
知道我可以做什么来使用极坐标来模仿下面的 pandas 代码吗?Polars 没有像 pandas 这样的索引,所以我不知道我能做什么。
df = pd.DataFrame(data = ([21,123], [132,412], [23, 43]), columns = ['c1', 'c2']).set_index("c1")
print(df.loc[[23, 132]])
Run Code Online (Sandbox Code Playgroud)
它打印
| c1 | c2 |
|---|---|
| 23 | 43 |
| 132 | 第412章 |
我唯一能想到的极坐标转换是
df = pl.DataFrame(data = ([21,123], [132,412], [23, 43]), schema = ['c1', 'c2'])
print(df.filter(pl.col("c1").is_in([23, 132])))
Run Code Online (Sandbox Code Playgroud)
但它打印
| c1 | c2 |
|---|---|
| 132 | 第412章 |
| 23 | 43 |
这没关系,但行不符合我给出的顺序。我给出了 [23, 132] 并希望输出行的顺序相同,就像 pandas 的输出一样。
是的,我可以稍后使用 sort() ,但是我使用它的原始数据有大约 3000 万行,所以我正在寻找尽可能快的东西。
我将一个名为gob的数据集加载到R中并尝试了方便的summary功能.值得注意的是,第三个四分位数小于平均值.怎么会这样?它是我的数据大小还是其他类似的东西?
我已经尝试为digits参数传递一个大值(例如10),但这并没有解决问题.
> summary(gob, digits=10)
customer_id 100101.D 100199.D 100201.D
Min. : 1083 Min. :0.0000000 Min. :0.0000000 Min. :0.0000000
1st Qu.: 965928 1st Qu.:0.0000000 1st Qu.:0.0000000 1st Qu.:0.0000000
Median :2448738 Median :0.0000000 Median :0.0000000 Median :0.0000000
Mean :2660101 Mean :0.0010027 Mean :0.0013348 Mean :0.0000878
3rd Qu.:4133368 3rd Qu.:0.0000000 3rd Qu.:0.0000000 3rd Qu.:0.0000000
Max. :6538193 Max. :1.0000000 Max. :1.0000000 Max. :0.7520278
Run Code Online (Sandbox Code Playgroud)
请注意,对于gob $ 100201.D,平均值为0.0000878,但是第3曲.= 0.
鉴于我有一个DataFrame,其列包含字符串列表,如下所示:
Name Fruit
0 Curly [Apple]
1 Moe [Orange]
2 Larry [Apple, Banana]
Run Code Online (Sandbox Code Playgroud)
我怎么把它变成这样的东西?
Name Fruit_Apple Fruit_Orange Fruit_Banana
0 Curly 1 0 0
1 Moe 0 1 0
2 Larry 1 0 1
Run Code Online (Sandbox Code Playgroud)
我有一种感觉,我会以某种方式使用,pandas.get_dummies()但我似乎无法得到它.有帮助吗?
scikit-learn是否有一个运行多个其他估算器的估算器并自动选择性能最佳的估算器(例如根据其交叉验证分数)?
我相信在符合估算器接口的类中必须有这样的东西,以便它可以在管道中组合- 正确吗?
我正在阅读一本关于Python的数据科学的书,作者应用'sigma-clipping operation'来删除因拼写错误而导致的异常值.但是,该过程根本没有解释.
什么是sigma剪辑?它是否仅适用于某些数据(例如,它用于美国的出生率)?
根据文字:
quartiles = np.percentile(births['births'], [25, 50, 75]) #so we find the 25th, 50th, and 75th percentiles
mu = quartiles[1] #we set mu = 50th percentile
sig = 0.74 * (quartiles[2] - quartiles[0]) #???
This final line is a robust estimate of the sample mean, where the 0.74 comes
from the interquartile range of a Gaussian distribution.
Run Code Online (Sandbox Code Playgroud)
为何0.74?有证据吗?
这是用于特征缩放的代码,其中我正在使用fit_transfrom()和transfrom()。
##Feature scaling
from sklearn.preprocessing import StandardScaler
sc_x=StandardScaler()
X_train=sc_x.fit_transform(X_train)
X_test=sc_x.transform(X_test)
Run Code Online (Sandbox Code Playgroud) 我有两个列表my_genre和list_of_genres。我想要一个函数来检查是否my_list[index]在list_of_genres并转换list_of_genres[index2]成1if的情况。
list_of_genres = ['Adventure', 'Animation', 'Children', 'Comedy', 'Fantasy', 'Drama', 'Romance', 'Action', 'Thriller', 'Sci-Fi', 'Crime', 'Horror', 'Mystery', 'IMAX', 'Documentary', 'War', 'Musical', 'Western', 'Film-Noir']
my_genre = ['Action', 'Crime', 'Drama', 'Thriller']
Run Code Online (Sandbox Code Playgroud)
预期结果:
[0 0 0 0 0 1 0 1 1 0 1 0 0 0 0 0 0 0 0]
data type : np.array
Run Code Online (Sandbox Code Playgroud)
最终,我想将执行此操作的功能应用于包含流派的pandas列。
data-science ×10
python ×8
pandas ×4
numpy ×3
scikit-learn ×2
finance ×1
list ×1
mean ×1
quartile ×1
querying ×1
r ×1
statistics ×1
yfinance ×1