小编MJP*_*MJP的帖子

AttributeError:只能使用带有字符串值的.str访问器,它在pandas中使用np.object_ dtype

Str.replace方法返回属性错误.

dc_listings['price'].str.replace(',', '')
AttributeError: Can only use .str accessor with string values, which use np.object_ dtype in pandas
Run Code Online (Sandbox Code Playgroud)

以下是我的价格列的前5行.

在此输入图像描述

此堆栈溢出线程建议检查我的列是否具有NAN值,但我的列中的值是否为NAN. 在此输入图像描述

python pandas

14
推荐指数
2
解决办法
2万
查看次数

如何根据列值切片pandas数据帧?

我有一个pandas数据框,格式如下:

year    col1 
y1      val_1 
y1      val_2
y1      val_3
y2      val_4
y2      val_5
y2      val_6
y3      val_7
y3      val_8
y3      val_9
Run Code Online (Sandbox Code Playgroud)

如何仅选择直到第2年的值并省略第3年?

我需要一个new_data框架如下:

   year      col1 
    y1      val_1 
    y1      val_2
    y1      val_3
    y2      val_4
    y2      val_5
    y2      val_6
Run Code Online (Sandbox Code Playgroud)

y1, y2, y3 代表年份价值

python python-2.7 pandas

7
推荐指数
1
解决办法
1万
查看次数

从 pandas 数据框中获取数组的子集

我有一个 numpy 数组,arr其中包含 1154 个元素。

array([502, 502, 503, ..., 853, 853, 853], dtype=int64)
Run Code Online (Sandbox Code Playgroud)

我有一个名为的数据框df

    team    Count
0   512     11
1   513     21
2   515     18
3   516     8
4   517     4
Run Code Online (Sandbox Code Playgroud)

如何获取df仅包含数组中的值的数据框的子集arr

例如:

team         count
arr1_value1    45
arr1_value2    67
Run Code Online (Sandbox Code Playgroud)

为了使这个问题更清楚:我有一个 numpy 数组['45', '55', '65']

我有一个数据框如下:

team  count
34      156
45      189
53       90
65       99
23       77
55       91
Run Code Online (Sandbox Code Playgroud)

我需要一个新的数据框,如下所示:

team    count
 45      189
 55       91
 65       99
Run Code Online (Sandbox Code Playgroud)

python numpy python-2.7 pandas

3
推荐指数
1
解决办法
5098
查看次数

计算 pandas 中的列值

dictionary = {'Year': [1985, 1985, 1986, 1986, 1987, 1987, 1987]}
pdf = pd.DataFrame(dictionary)

    Year
0   1985
1   1985
2   1986
3   1986
4   1987
5   1987
6   1987
Run Code Online (Sandbox Code Playgroud)

我有一个名为pdf我需要形成new data frame以下格式的数据框:

Year   count
1985     2
1986     2 
1987     3
Run Code Online (Sandbox Code Playgroud)

如何在 pandas 中有效地做到这一点?

python python-2.7 pandas

2
推荐指数
1
解决办法
2493
查看次数

标签 统计

pandas ×4

python ×4

python-2.7 ×3

numpy ×1