在Spark DataFrame中添加一个新列,其中包含一个列的所有值的总和-Scala / Spark

时间:2019-01-23 04:10:27

标签: scala apache-spark dataframe apache-spark-sql

This is the snapshot which is takes after adding a column but that does not contain the sum of all values of one column

我正在尝试在数据框中添加一列,其中包含同一数据框中一列的所有值的总和。

例如: 图片中有列-UserID,MovieID,Rating,Unixtimestamp。 现在,我想添加一个名为Sum的列,其中将包含Rating Column的所有值的总和。

我有一个评分数据框

Ratings DataFrame列名称:USerID,MovieID,Ratings,UnixTimeStamp。

+------+-------+------+-------------+
|UserID|MovieID|Rating|UnixTimeStamp|
+------+-------+------+-------------+
|   196|    242|     3|    881250949|
|   186|    302|     3|    891717742|
|    22|    377|     1|    878887116|
|   244|     51|     2|    880606923|
|   166|    346|     1|    886397596|
+------+-------+------+-------------+

仅显示前5行

我必须计算wa等级并将其存储到数据框中。

wa_rating =(rating> 3)/总评分

请帮助我找到wa_rating数据框,其中包含一个使用scala spark的新列

1 个答案:

答案 0 :(得分:2)

检查一下:

public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
    {

        public override bool FinishedLaunching(UIApplication uiApplication, NSDictionary launchOptions)
        {
            Rg.Plugins.Popup.Popup.Init();
            CachedImageRenderer.Init();
            global::Xamarin.Forms.Forms.Init();
            LoadApplication(new App());
            FirebasePushNotificationManager.Initialize(launchOptions, true);
            FirebasePushNotificationManager.CurrentNotificationPresentationOption = UNNotificationPresentationOptions.Alert | UNNotificationPresentationOptions.Badge;
            UNUserNotificationCenter.Current.Delegate = new UserNotificationCenterDelegate();
            return base.FinishedLaunching(uiApplication, launchOptions);
        }
        public class UserNotificationCenterDelegate : UNUserNotificationCenterDelegate
        {
            public UserNotificationCenterDelegate()
            {
            }

            public override void WillPresentNotification(UNUserNotificationCenter center, UNNotification notification, Action<UNNotificationPresentationOptions> completionHandler)
            {
                // Do something with the notification
                Console.WriteLine("Active Notification: {0}", notification);

                // Tell system to display the notification anyway or use
                // `None` to say we have handled the display locally.
                completionHandler(UNNotificationPresentationOptions.Alert);
            }
        }
        public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
        {
            FirebasePushNotificationManager.DidRegisterRemoteNotifications(deviceToken);
        }

        public override void FailedToRegisterForRemoteNotifications(UIApplication application, NSError error)
        {
            FirebasePushNotificationManager.RemoteNotificationRegistrationFailed(error);

        }

        public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler)
        {

            FirebasePushNotificationManager.DidReceiveMessage(userInfo);
            // Do your magic to handle the notification data
            System.Console.WriteLine(userInfo);

            completionHandler(UIBackgroundFetchResult.NewData);
        }
    }