我正在尝试阅读 Movie Lens 数据集:http://files.grouplens.org/datasets/movielens/ml-100k/。
我正在使用 Python 3.4 版,并且正在遵循此处给出的教程“ http://www.gregreda.com/2013/10/26/using-pandas-on-the-movielens-dataset/ ”。
当我尝试使用那里提到的代码读取 u.item 数据时:
# the movies file contains columns indicating the movie's genres
# let's only load the first five columns of the file with usecols
m_cols = ['movie_id', 'title', 'release_date', 'video_release_date', 'imdb_url']
movies = pd.read_csv('ml-100k/u.item', sep='|', names=m_cols, usecols=range(5), encoding='UTF-8')
Run Code Online (Sandbox Code Playgroud)
我收到以下错误“UnicodeDecodeError:‘utf-8’编解码器无法解码位置 3 中的字节 0xe9:无效的连续字节”。
此错误的可能原因是什么以及解决方案是什么
我尝试将encoding='utf-8'添加到pd.read_csv(encoding='utf-8'),但不幸的是它没有解决任何问题。
错误回溯是:
---------------------------------------------------------------------------
UnicodeDecodeError Traceback (most recent call last)
<ipython-input-4-4cc01a7faf02> in <module>()
9 # let's only load the first five columns of the …Run Code Online (Sandbox Code Playgroud) 据我所知,Python中没有AIC包。因此,我尝试手动计算它,以找到数据集中的最佳聚类数量(我使用 K 均值进行聚类)
我在Wiki上遵循等式:
AIC = 2k - 2ln(最大似然)
下面是我当前的代码:
range_n_clusters = range(2, 10)
for n_clusters in range_n_clusters:
model = cluster.KMeans(n_clusters=n_clusters, init='k-means++', n_init=10, max_iter=300, tol=0.0001,
precompute_distances='auto', verbose=0, random_state=None, copy_x=True, n_jobs=1)
model.fit(X)
centers = model.cluster_centers_
labels = model.labels_
likelihood = ?????
aic = 2 * len(X.columns) - 2 * likelihood
print(aic)
Run Code Online (Sandbox Code Playgroud)
有关如何计算似然值的任何指示吗?
// 更新:使用高斯混合模型计算 AIC:
它不是应该看起来像一条曲线吗?(而不是直线)
我的绘图代码:
def aic(X):
range_n_clusters = range(2, 10)
aic_list = []
for n_clusters in range_n_clusters:
model = mixture.GaussianMixture(n_components=n_clusters, init_params='kmeans')
model.fit(X)
aic_list.append(model.aic(X))
plt.plot(range_n_clusters, aic_list, …Run Code Online (Sandbox Code Playgroud) 我有一个 df,
0 1 2 A
-0.740485792 -0.299824912 0.169113705 1
1.120120949 -0.62580736 0.013757667 2
-0.685112999 0.439492717 -0.484524907 3
Run Code Online (Sandbox Code Playgroud)
我正在尝试获取所有值都大于 0 的列名,
我试过(df > 0).all()
Out[47]:
0 False
1 False
2 False
A True
dtype: bool
Run Code Online (Sandbox Code Playgroud)
如何仅获取 True 的列名,
我的预期输出是“A”,提前致谢。
关于sort_index()的问题2
df2 = pd.DataFrame({"A":[3,2,1]}, index=[2,1,0])
Out[395]:
A
2 3
1 2
0 1
df2.sort_index(axis=1)
A
2 3
1 2
0 1
Run Code Online (Sandbox Code Playgroud)
预期输出是
A
0 3
1 2
2 1
Run Code Online (Sandbox Code Playgroud) 我有一个 df,
A B
one six
two seven
three level
five one
Run Code Online (Sandbox Code Playgroud)
和一本字典
my_dict={1:"one,two",2:"three,four"}
Run Code Online (Sandbox Code Playgroud)
我想用 my_dict keys() 替换 df.A。
我想要的输出是,
A B
1 six
1 seven
2 level
five one
Run Code Online (Sandbox Code Playgroud)
我尝试过df.A.replace(my_dict,regex=True),但没有成功。
我是 Power BI 和 DAX 的新手,所以我希望你能帮助我。
我有两个没有任何关系的表: 表 A包含跟踪位置的纬度/经度和日期。 表 B包含所有体育场的纬度/经度和名称。
我想找到靠近跟踪位置的最近的体育场。另外,如果可能的话,我想验证该位置是否在该体育场的特定半径内。
非常感谢任何帮助。
我有两个传感器A和B。我正在尝试使用扩展卡尔曼滤波器合并他们的传感器数据,以进行高效的数据分析。由于数据类型是非线性的,因此我使用扩展卡尔曼滤波器。就我而言,来自传感器A的数据始终可靠,但来自传感器B的数据的可靠性随时间变化。例如,在 时t=0,其可靠性很高,并且可靠性逐渐(均匀)下降,直到t=T。在这种情况下,如何结合传感器数据以获得更好的优化结果?或者如何为来自传感器Bt=0的数据分配动态权重?t=T
更新:我必须在 EKF 的预测阶段使用来自传感器B的数据。
我正在尝试在我的 Google Colab 笔记本中使用Pandas_Profiling.ProfilingReport。这是我的代码:
import pandas_profiling
profile = pandas_profiling.ProfileReport(df)
Run Code Online (Sandbox Code Playgroud)
并得到该错误:
" concat() got an unexpected keyword argument 'join_axes' "
Run Code Online (Sandbox Code Playgroud) 我想更改该图中的颜色,它可以正确地可视化数据,但正如您所看到的,它不容易阅读,因为所有这些颜色都非常相似(7 个类别)。有简单的方法吗?生成绘图的代码:
sns.pairplot(data, kind="scatter", hue = "Class")
Run Code Online (Sandbox Code Playgroud)
我正在从事一些分析工作,我们需要将数据从一个来源转换到另一个来源,我们正在使用DBT进行转换。仅可通过 REST API 使用的数据之一。所以我的问题是我们可以在 dbt 文件中调用外部 API 并从其响应中提取字段吗?我们有东西吗?
我该怎么做:
from tqdm.notebook import tqdm
from matplotlib import pyplot as plt
from IPython import display
import time
import numpy as np
xx = list()
for i in tqdm(range(500)):
xx.append(i * 0.1)
yy = np.sin(xx)
if i % 10 == 0:
display.clear_output(wait=True)
plt.plot(xx, yy)
time.sleep(0.1)
Run Code Online (Sandbox Code Playgroud)
但是tqdm当我更新情节时防止进度条消失?
data-analysis ×10
python ×7
pandas ×4
dataframe ×2
api ×1
coordinates ×1
csv ×1
dax ×1
dbt ×1
filtering ×1
matplotlib ×1
plot ×1
powerbi ×1
powerpivot ×1
python-3.x ×1
scikit-learn ×1
seaborn ×1
sensors ×1
tqdm ×1