<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Pivot Raw Data in Data &amp; Schema Discussions</title>
    <link>https://community.incorta.com/t5/data-schema-discussions/pivot-raw-data/m-p/4822#M383</link>
    <description>&lt;P&gt;&lt;a href="https://community.incorta.com/t5/user/viewprofilepage/user-id/895"&gt;@rahabib&lt;/a&gt;&amp;nbsp; - I was looking to understand a little more on what you are looking for.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Are you looking to use other languages like Spark Scala or Spark R? Or are you looking to use python for easier-to-express functions?&lt;BR /&gt;Pyspark Example:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;# Sample data
data = [
    ("Alice", "Math", 90),
    ("Alice", "Physics", 85),
    ("Bob", "Math", 75),
    ("Bob", "Physics", 80),
    ("Alice", "Chemistry", 88),
    ("Bob", "Chemistry", 92)
]

# Create a DataFrame
columns = ["student", "subject", "score"]
df = spark.createDataFrame(data, columns)

# Pivot the table
pivot_df = df.groupBy("student").pivot("subject").agg({"score": "first"})

pivot_df.show()&lt;/LI-CODE&gt;
&lt;P&gt;PySpark using Pandas example:&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;import pandas as pd
data = [
    ("Alice", "Math", 90),
    ("Alice", "Physics", 85),
    ("Bob", "Math", 75),
    ("Bob", "Physics", 80),
    ("Alice", "Chemistry", 88),
    ("Bob", "Chemistry", 92)
]

# Create a DataFrame
columns = ["student", "subject", "score"]
df = pd.DataFrame(data, columns=columns)

# Pivot the table
pivot_df = df.pivot(index="student", columns="subject", values="score")

print(pivot_df)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 14 Aug 2023 15:42:20 GMT</pubDate>
    <dc:creator>JoeM</dc:creator>
    <dc:date>2023-08-14T15:42:20Z</dc:date>
    <item>
      <title>Pivot Raw Data</title>
      <link>https://community.incorta.com/t5/data-schema-discussions/pivot-raw-data/m-p/4809#M382</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;Is there any way to Pivot some of the raw data columns (not in PySpark) prior to using the data for analytics?&lt;/P&gt;&lt;P&gt;Also, Is there any way to use Python instead of PySpark in the MV creation?&lt;/P&gt;</description>
      <pubDate>Sun, 13 Aug 2023 11:08:38 GMT</pubDate>
      <guid>https://community.incorta.com/t5/data-schema-discussions/pivot-raw-data/m-p/4809#M382</guid>
      <dc:creator>rahabib</dc:creator>
      <dc:date>2023-08-13T11:08:38Z</dc:date>
    </item>
    <item>
      <title>Re: Pivot Raw Data</title>
      <link>https://community.incorta.com/t5/data-schema-discussions/pivot-raw-data/m-p/4822#M383</link>
      <description>&lt;P&gt;&lt;a href="https://community.incorta.com/t5/user/viewprofilepage/user-id/895"&gt;@rahabib&lt;/a&gt;&amp;nbsp; - I was looking to understand a little more on what you are looking for.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Are you looking to use other languages like Spark Scala or Spark R? Or are you looking to use python for easier-to-express functions?&lt;BR /&gt;Pyspark Example:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;# Sample data
data = [
    ("Alice", "Math", 90),
    ("Alice", "Physics", 85),
    ("Bob", "Math", 75),
    ("Bob", "Physics", 80),
    ("Alice", "Chemistry", 88),
    ("Bob", "Chemistry", 92)
]

# Create a DataFrame
columns = ["student", "subject", "score"]
df = spark.createDataFrame(data, columns)

# Pivot the table
pivot_df = df.groupBy("student").pivot("subject").agg({"score": "first"})

pivot_df.show()&lt;/LI-CODE&gt;
&lt;P&gt;PySpark using Pandas example:&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;import pandas as pd
data = [
    ("Alice", "Math", 90),
    ("Alice", "Physics", 85),
    ("Bob", "Math", 75),
    ("Bob", "Physics", 80),
    ("Alice", "Chemistry", 88),
    ("Bob", "Chemistry", 92)
]

# Create a DataFrame
columns = ["student", "subject", "score"]
df = pd.DataFrame(data, columns=columns)

# Pivot the table
pivot_df = df.pivot(index="student", columns="subject", values="score")

print(pivot_df)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Aug 2023 15:42:20 GMT</pubDate>
      <guid>https://community.incorta.com/t5/data-schema-discussions/pivot-raw-data/m-p/4822#M383</guid>
      <dc:creator>JoeM</dc:creator>
      <dc:date>2023-08-14T15:42:20Z</dc:date>
    </item>
  </channel>
</rss>

