0

Currently I have this dataframe(df):

    +-------------------+--------+
    |       datetime_new|pkts_new|
    +-------------------+--------+
    |2018-01-04 00:00:00|    47.0|
    |2018-01-04 00:00:00|     1.0|
    |2018-01-04 00:00:00|     3.0|
    |2018-01-04 00:00:00|    40.0|
    |2018-01-04 00:01:00|     1.0|
    |2018-01-04 00:01:00|     1.0|
    |2018-01-04 00:01:00|     1.0|
    |2018-01-04 00:01:00|    49.0|
    |2018-01-04 00:01:00|    33.0|
    |2018-01-04 00:01:00|     2.0|
    +-------------------+--------+

`DataFrame[datetime_new: timestamp, pkts_new: double]`

type(t): <class 'pyspark.sql.dataframe.DataFrame'>

I want to plot a line chart where the x axis is datetime_new, and the y axis is pkts_new. However, when i used this command: plt.plot(df.select('datetime_new'),df.select('pkts_new')) , I will get the error message:ValueError: setting an array element with a sequence.

How do I plot a line chart for ?

1 Answer 1

0

Convert array into list using list(myarray)

import matplotlib.pyplot as plt    
plt.plot(data_time,time)
plt.show()
Sign up to request clarification or add additional context in comments.

7 Comments

If i were to type plt.plot(list(df.select("datetime_new")),list(df.select("pkts_new"))), the error will still be the same
convert the array in list at prior stage during plotting it will not convert to list, and plotting needs list for axis
t_dt = list(df.select("datetime_new")) t_pkt = list(df.select("pkts_new")) plt.plot(t_dt , t_pkt) plt.show() wil still give me the same error message. can u show me an example please? Thanks
stackoverflow.com/a/22341390/4683899 refer this link for conversion
plt.plot(df['datetime_new'].tolist(),df['pkts_new'].tolist()) I guess this will help
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.