Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot convert DataFrame to series data for plotting in julia

Tags:

julia

I'm learning julia from https://docs.juliaplots.org/latest/basics/ Here is the julia code

using Plots,UnicodePlots,RDatasets
unicodeplots()
v=dataset("Ecdat","Airline")
typeof(v)
plot(v, :Cost) # this line will produce the error
plot(v) # this line will produce the error, too

I got

ERROR: Cannot convert DataFrame to series data for plotting
Stacktrace:
 [1] prepareSeriesData(::DataFrame) at /home/dlin/.julia/packages/Plots/qZHsp/src/series.jl:14
 [2] convertToAnyVector(::DataFrame, ::Dict{Symbol,Any}) at /home/dlin/.julia/packages/Plots/qZHsp/src/series.jl:26
 [3] macro expansion at /home/dlin/.julia/packages/Plots/qZHsp/src/series.jl:130 [inlined]
 [4] apply_recipe(::Dict{Symbol,Any}, ::Type{Plots.SliceIt}, ::Nothing, ::DataFrame, ::Nothing) at /home/dlin/.julia/packages/RecipesBase/zBoFG/src/RecipesBase.jl:275
 [5] _process_userrecipes(::Plots.Plot{Plots.GRBackend}, ::Dict{Symbol,Any}, ::Tuple{DataFrame}) at /home/dlin/.julia/packages/Plots/qZHsp/src/pipeline.jl:83
 [6] _plot!(::Plots.Plot{Plots.GRBackend}, ::Dict{Symbol,Any}, ::Tuple{DataFrame}) at /home/dlin/.julia/packages/Plots/qZHsp/src/plot.jl:178
 [7] #plot#138(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::typeof(plot), ::DataFrame) at /home/dlin/.julia/packages/Plots/qZHsp/src/plot.jl:57
 [8] plot(::DataFrame) at /home/dlin/.julia/packages/Plots/qZHsp/src/plot.jl:51
 [9] top-level scope at REPL[4]:1

In the code of series.jl, it is

prepareSeriesData(x) = error("Cannot convert $(typeof(x)) to series data for plotting")

How to correct this?

like image 607
Daniel YC Lin Avatar asked Dec 23 '19 02:12

Daniel YC Lin


People also ask

How do I convert a single row in a Dataframe to series?

Single row in the DataFrame into a Series (1) Convert a Single DataFrame Column into a Series To start with a simple example, let’s create a DataFrame with a single column: import pandas as pd data = {'First_Name': ['Jeff','Tina','Ben','Maria','Rob']} df = pd.DataFrame (data, columns = ['First_Name']) print (df) print (type (df))

How to convert a pandas Dataframe to a series?

You can convert Pandas DataFrame to a Series using squeeze: In this guide, you’ll see 3 scenarios of converting: To start with a simple example, let’s create a DataFrame with a single column:

How do I use pyplots in Julia?

The PyPlots module provides a Julia interface to the Matplotlib plotting library from Python. Although PyPlots is a distribution of Python and matplotlib, Julia can install a private distribution that can’t be accessed outside Julia’s environment. Open a new terminal window and run Julia.

How to create a Dataframe with a single column in Python?

To start with a simple example, let’s create a DataFrame with a single column: Run the code in Python, and you’ll get the following DataFrame (note that print (type (df)) was added at the bottom of the code to demonstrate that we got a DataFrame):


Video Answer


1 Answers

What about simply using plot(v.Cost):

julia> plot(v.Cost)
                      ┌────────────────────────────────────────────────────────────┐
         4.88870026e6 │⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⣠⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ y1
                      │⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
                      │⠀⡇⠀⠀⠀⠀⠀⠀⠀⢰⢹⠀⠀⠀⠀⠀⠀⠀⠀⢀⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
                      │⠀⡇⠀⠀⠀⠀⠀⠀⠀⡎⢸⠀⠀⠀⠀⠀⠀⠀⠀⡸⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
                      │⠀⡇⠀⠀⠀⠀⠀⢀⠎⠀⢸⠀⠀⠀⠀⠀⠀⠀⢠⠃⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
                      │⠀⡇⠀⠀⠀⠀⠀⢸⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⡇⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
                      │⠀⡇⠀⠀⠀⠀⠀⡎⠀⠀⢸⠀⠀⠀⠀⠀⠀⢸⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
                      │⠀⡇⠀⠀⠀⠀⠀⡇⠀⠀⢸⠀⠀⠀⠀⠀⠀⡎⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
                      │⠀⡇⠀⠀⠀⠀⢰⠁⠀⠀⢸⠀⠀⠀⠀⠀⠀⡇⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
                      │⠀⡇⠀⠀⠀⠀⡸⠀⠀⠀⢸⠀⠀⠀⠀⠀⢰⠁⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
                      │⠀⡇⠀⠀⠀⢀⠇⠀⠀⠀⢸⠀⠀⠀⠀⠀⢸⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
                      │⠀⡇⠀⠀⠀⡼⠀⠀⠀⠀⠈⡆⠀⠀⠀⠀⡇⠀⠀⠀⢣⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
                      │⠀⡇⠀⠀⡰⠁⠀⠀⠀⠀⠀⡇⠀⠀⠀⢰⠁⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
                      │⠀⡇⠀⡰⠁⠀⠀⠀⠀⠀⠀⡇⠀⠀⢠⠇⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
                      │⠀⡇⡰⠁⠀⠀⠀⠀⠀⠀⠀⡇⠀⢀⠇⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⣀⠀⠀⠀⠀⠀⠀⠀⢀⠜⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
                      │⠀⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⡎⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⢀⠜⠊⢸⠀⠀⠀⠀⠀⠀⢀⠎⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡄⠀│
                      │⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⡼⠀⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⢠⠋⠀⠀⢸⠀⠀⠀⠀⠀⠀⡎⠀⠀⢱⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡜⠀⠀│
                      │⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠋⠀⠀⠀⠀⠀⠀⠀⠀⢸⠀⠀⡠⠒⠁⠀⠀⠀⠀⡇⠀⠀⠀⢀⠜⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⡠⠔⢲⠀⠀⠀⠀⠀⠀⠀⡔⠁⠀⠀│
                      │⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠸⠒⠊⠀⠀⠀⠀⠀⠀⠀⡇⡠⠖⠉⠁⠀⠀⠀⠀⢸⠀⠀⠀⢀⡠⠒⠁⠀⠈⡆⠀⠀⠀⠀⡠⠎⠀⠀⠀⠀│
   -71402.26000000001 │⠤⡧⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠭⠤⠤⠤⠤⠤⠤⠤⠤⠼⠶⠾⠭⠥⠤⠤⠤⠤⠤⠷⠶⠾⠭⠭⠤⠤⠤⠤⠤⠤│
                      └────────────────────────────────────────────────────────────┘
                      -1.67                                                    92.67
like image 73
Przemyslaw Szufel Avatar answered Sep 19 '22 13:09

Przemyslaw Szufel