【发布时间】:2020-03-09 16:01:57
【问题描述】:
我有一个数据框,我想对该列的所有值进行切片,但我不知道该怎么做?
我的数据框
+-------------+------+
| studentID|gender|
+-------------+------+
|1901000200 | M|
|1901000500 | M|
|1901000500 | M|
|1901000500 | M|
|1901000500 | M|
+-------------+------+
我已将 studentID 转换为字符串,但无法从中删除前 190 个。我想要下面的输出。
+-------------+------+
| studentID|gender|
+-------------+------+
| 1000200 | M|
| 1000500 | M|
| 1000500 | M|
| 1000500 | M|
| 1000500 | M|
+-------------+------+
我尝试了以下方法,但它给了我错误。
students_data = students_data.withColumn('studentID',F.lit(students_data["studentID"][2:]))
TypeError: startPos and length must be the same type. Got <class 'int'> and <class 'NoneType'>, respectively.
【问题讨论】:
-
是的,我也是这样做的,但是当我尝试再次将
studentID转换为 int 时,它给了我一些奇怪的负整数值。
标签: python dataframe pyspark apache-spark-sql pyspark-sql