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.
我有一个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
代表年份价值
我有一个 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) 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 中有效地做到这一点?