我有一个非常大的df,很多行和列。如果分类变量的类别小于模式计数的0.5%,我想将其重命名为"other“。
我知道df[colname].value_counts(normalize=True)给了我所有类别的分布。如何提取小于0.5%的模式,以及如何将其重命名为other?
apple
large 100
medium 50
small 3
desired output
apple
large 100
medium 50
other 3
我需要检查一个特定的值在pandas dataframe列中是否多次存在。这是基本的代码;
for index, row in df_x.iterrows():
try:
if row[1] in df_y['b'].values:
# if row[1] exists in df_y i want to know how many time is it repeated, or if it is unique or not
except Exception as e:
print('Error ', e)
我有这样的数据帧 City Gender
0 A M
1 B F
2 C F
3 A M
4 A M
5 B F 然后,我想使用.nunique on City列来了解表中有多少内容占据了前两个位置 我从https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.nunique.html那里学到了很多东西,我试着运行这个 df_dataset['City'].nunique() 但是有些事情是不合理的
我有一个系列,其中包括一些随机产品的列表。这就是如果我打印描述的样子:
<bound method NDFrame.describe of 176 reversible jacket
231 the north face resolve 2 jacket
234 columbia pike lake jacket
279 girl's 7-16 knitworks skater belted dress
当我试图在ipython...beginner中与熊猫一起运行这个文件时,我总是得到不同的属性错误,所以我可能遗漏了什么
代码:
from pandas import Series, DataFrame
import pandas as pd
import json
nan=float('NaN')
data = []
with open('file.json') as f:
for line in f:
data.append(json.loads(line))
df = DataFrame(data, columns=['accept
我有这个数据集,有5列和很多行。我被要求得到男性和女性的总数。它们是串的,无法弄清楚。我也得用numpy。请帮帮忙。谢谢
ls = gender.values.tolist()
ls
top = []
for i in ls:
if i == 'M':
top.append(i)
print(i)
I need to sum of the male and female in the above dataset.
我有一张有很多行的数据。有时价值观是其中之一,对我的目的没有多大用处。
如何删除列2和3的值不超过5次的所有行?
df输入
Col1 Col2 Col3 Col4
1 apple tomato banana
1 apple potato banana
1 apple tomato banana
1 apple tomato banana
1 apple tomato banana
1 apple
我有一个有一个列的DataFrame df,category是用下面的代码创建的:
import pandas as pd
import random as rand
from string import ascii_uppercase
rand.seed(1010)
df = pd.DataFrame()
values = list()
for i in range(0,1000):
category = (''.join(rand.choice(ascii_uppercase) for i in range(1)))
values.append(c
我正在处理一个数据帧,有几个数据列缺少由列中的'?'表示的目录。我正在尝试使用布尔值来重命名,并在标记为workclass的列中将缺少的标记为'?'的类别替换为'Private'。数据以如下方式读入: import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from pandas.plotting import scatter_matrix
from sklearn.preprocessing import *
url2="https://archi
基于(简化的) DataFrame
import pandas as pd
texts = pd.DataFrame({"description":["This is one text","and this is another one"]})
print(texts)
description
0 This is one text
1 and this is another on
我想用描述列中一组单词的词频创建系列。
预期结果如下:
counts
this 2
i