@@ -1202,6 +1202,106 @@ public actor DataFrame: Sendable {
12021202 return dropDuplicates ( )
12031203 }
12041204
1205+ /// Transposes a DataFrame, switching rows to columns. This function transforms the DataFrame
1206+ /// such that the values in the first column become the new columns of the DataFrame.
1207+ /// - Returns: A transposed ``DataFrame``.
1208+ public func transpose( ) -> DataFrame {
1209+ return buildTranspose ( [ ] )
1210+ }
1211+
1212+ /// Unpivot a DataFrame from wide format to long format, optionally leaving identifier columns
1213+ /// set. This is the reverse to `groupBy(...).pivot(...).agg(...)`, except for the aggregation,
1214+ /// which cannot be reversed. This is an alias for `unpivot`.
1215+ /// - Parameters:
1216+ /// - ids: ID column names
1217+ /// - values: Value column names to unpivot
1218+ /// - variableColumnName: Name of the variable column
1219+ /// - valueColumnName: Name of the value column
1220+ /// - Returns: A ``DataFrame``.
1221+ public func melt(
1222+ _ ids: [ String ] ,
1223+ _ values: [ String ] ,
1224+ _ variableColumnName: String ,
1225+ _ valueColumnName: String
1226+ ) -> DataFrame {
1227+ return unpivot ( ids, values, variableColumnName, valueColumnName)
1228+ }
1229+
1230+ /// Unpivot a DataFrame from wide format to long format, optionally leaving identifier columns
1231+ /// set. This is the reverse to `groupBy(...).pivot(...).agg(...)`, except for the aggregation,
1232+ /// which cannot be reversed. This is an alias for `unpivot`.
1233+ /// - Parameters:
1234+ /// - ids: ID column names
1235+ /// - variableColumnName: Name of the variable column
1236+ /// - valueColumnName: Name of the value column
1237+ /// - Returns: A ``DataFrame``.
1238+ public func melt(
1239+ _ ids: [ String ] ,
1240+ _ variableColumnName: String ,
1241+ _ valueColumnName: String
1242+ ) -> DataFrame {
1243+ return unpivot ( ids, variableColumnName, valueColumnName)
1244+ }
1245+
1246+ /// Unpivot a DataFrame from wide format to long format, optionally leaving identifier columns
1247+ /// set. This is the reverse to `groupBy(...).pivot(...).agg(...)`, except for the aggregation,
1248+ /// which cannot be reversed.
1249+ /// - Parameters:
1250+ /// - ids: ID column names
1251+ /// - values: Value column names to unpivot
1252+ /// - variableColumnName: Name of the variable column
1253+ /// - valueColumnName: Name of the value column
1254+ /// - Returns: A ``DataFrame``.
1255+ public func unpivot(
1256+ _ ids: [ String ] ,
1257+ _ values: [ String ] ,
1258+ _ variableColumnName: String ,
1259+ _ valueColumnName: String
1260+ ) -> DataFrame {
1261+ return buildUnpivot ( ids, values, variableColumnName, valueColumnName)
1262+ }
1263+
1264+ /// Unpivot a DataFrame from wide format to long format, optionally leaving identifier columns
1265+ /// set. This is the reverse to `groupBy(...).pivot(...).agg(...)`, except for the aggregation,
1266+ /// which cannot be reversed.
1267+ /// - Parameters:
1268+ /// - ids: ID column names
1269+ /// - variableColumnName: Name of the variable column
1270+ /// - valueColumnName: Name of the value column
1271+ /// - Returns: A ``DataFrame``.
1272+ public func unpivot(
1273+ _ ids: [ String ] ,
1274+ _ variableColumnName: String ,
1275+ _ valueColumnName: String
1276+ ) -> DataFrame {
1277+ return buildUnpivot ( ids, nil , variableColumnName, valueColumnName)
1278+ }
1279+
1280+ func buildUnpivot(
1281+ _ ids: [ String ] ,
1282+ _ values: [ String ] ? ,
1283+ _ variableColumnName: String ,
1284+ _ valueColumnName: String ,
1285+ ) -> DataFrame {
1286+ let plan = SparkConnectClient . getUnpivot ( self . plan. root, ids, values, variableColumnName, valueColumnName)
1287+ return DataFrame ( spark: self . spark, plan: plan)
1288+ }
1289+
1290+ /// Transposes a ``DataFrame`` such that the values in the specified index column become the new
1291+ /// columns of the ``DataFrame``.
1292+ /// - Parameter indexColumn: The single column that will be treated as the index for the transpose operation.
1293+ /// This column will be used to pivot the data, transforming the DataFrame such that the values of
1294+ /// the indexColumn become the new columns in the transposed DataFrame.
1295+ /// - Returns: A transposed ``DataFrame``.
1296+ public func transpose( _ indexColumn: String ) -> DataFrame {
1297+ return buildTranspose ( [ indexColumn] )
1298+ }
1299+
1300+ func buildTranspose( _ indexColumn: [ String ] ) -> DataFrame {
1301+ let plan = SparkConnectClient . getTranspose ( self . plan. root, indexColumn)
1302+ return DataFrame ( spark: self . spark, plan: plan)
1303+ }
1304+
12051305 /// Groups the DataFrame using the specified columns.
12061306 ///
12071307 /// This method is used to perform aggregations on groups of data.
0 commit comments