Code Monkey home page Code Monkey logo

Comments (5)

ljluestc avatar ljluestc commented on May 25, 2024
import databricks.koalas as ks
from pyspark import SparkConf
from pyspark.sql import SparkSession

if __name__ == '__main__':
    conf = SparkConf().setAppName("test")

    spark = SparkSession.builder.config(conf=conf).enableHiveSupport().getOrCreate()
    sdf = spark.sql("select uid,vr_id, gender, follow_count, byfollow_count, is_click "
                    "from database.table where data_date=20220726 "
                    "and uid=249462081764458496 limit 5")
    sdf.show(n=20)

    print("=======================to_koalas===============================")
    df = sdf.to_koalas()

    # Explicitly cast columns to the desired data types
    df["uid"] = df["uid"].astype("int64")
    df["vr_id"] = df["vr_id"].astype("int64")
    df["gender"] = df["gender"].astype("int32")
    df["follow_count"] = df["follow_count"].astype("int32")
    df["byfollow_count"] = df["byfollow_count"].astype("int32")
    df["is_click"] = df["is_click"].astype("int32")

    category_features_df = df[["uid", "vr_id", "gender"]].fillna(0)
    dense_features_df = df[["follow_count", "byfollow_count"]].fillna(0)

    y = df["is_click"].values

    print("category_features_df: {}".format(category_features_df))
    print("dense_features_df: {}".format(dense_features_df))

    total_uids = category_features_df["uid"].unique().tolist()
    total_vids = category_features_df["vr_id"].unique().tolist()
    uid_id2index = {uid: i for i, uid in enumerate(total_uids)}
    uid_index2id = {i: uid for uid, i in uid_id2index.items()}
    vid_id2index = {vid: i for i, vid in enumerate(total_vids)}
    vid_index2id = {i: vid for vid, i in vid_id2index.items()}
    print(f"uid_id2index: {uid_id2index}")
    print(f"vid_id2index: {vid_id2index}")

from koalas.

tsafacjo avatar tsafacjo commented on May 25, 2024

can I take it ?

from koalas.

itholic avatar itholic commented on May 25, 2024

@tsafacjo could you open a ticket on Spark JIRA and made a fix for pyspark.pandas instead of Koalas? This repository is no longer maintained since Koalas has been migrated into Apache Spark.

from koalas.

tsafacjo avatar tsafacjo commented on May 25, 2024

ok, thanks @itholic

from koalas.

itholic avatar itholic commented on May 25, 2024

np! please feel free to ping me if you want to any help for contributing Apache Spark.

from koalas.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.