考试报名
考试报名
考试内容
考试大纲
在线客服
返回顶部

备考刷题,请到

CDA认证小程序

假如我们导入了数据库,但没有对其值和日期建立索引,那么如何创建一个?
A. df.set_index('Date' = True)
B. df.set_index('Date'= true, in place = True)
C. df.set_index('Date', in place = True)
D. df.set_index(in_place=True)
上一题
下一题
收藏
点赞
评论
题目解析
题目评论(0)

正确答案是:C: `df.set_index('Date', inplace=True)`

分析:
- `df.set_index()` 是 Pandas 中用于设置 DataFrame 索引的方法。
- 选项 A 中 `'Date' = True` 是错误的语法,`'Date'` 应该是一个参数而非赋值操作。
- 选项 B 中的 `in place = True` 语法错误,正确的写法应该是 `inplace=True`,没有空格。
- 选项 D 中缺少必要的参数 `'Date'`,因此无法指定哪一列作为索引。

选项 C 正确地使用了 `df.set_index('Date', inplace=True)`,其中:
- `'Date'` 是要设置为索引的列名称。
- `inplace=True` 表示直接在原 DataFrame 上进行修改,而不是返回一个新的 DataFrame。