julia> DataFrames.DataFrame(df)
ERROR: MethodError: no method matching DataFrames.DataFrame(::Pandas.DataFrame)
Closest candidates are:
DataFrames.DataFrame(::Any, ::DataStreams.Data.Schema, ::Type{S}, ::Bool; reference) where S at /Users/tomkwong/.julia/packages/DataFrames/utxEh/src/abstractdataframe/io.jl:295
DataFrames.DataFrame(::Array{Any,1}, ::DataFrames.Index) at /Users/tomkwong/.julia/packages/DataFrames/utxEh/src/dataframe/dataframe.jl:87
DataFrames.DataFrame(; kwargs...) at /Users/tomkwong/.julia/packages/DataFrames/utxEh/src/dataframe/dataframe.jl:142
So I tried to convert a TypedTable to DataFrame as noted in IterableTablesβs README file and itβs giving weird results. Perhaps things got broken in the transition to 1.0?
julia> t = TypedTables.Table(a = [1, 2, 3], b = [2.0, 4.0, 6.0])
Table with 2 columns and 3 rows:
a b
ββββββββ
1 β 1 2.0
2 β 2 4.0
3 β 3 6.0
julia> DataFrames.DataFrame(t)
β Warning: passing columns argument with non-AbstractVector entries is deprecated
β caller = top-level scope at none:0
β @ Core none:0
1Γ3 DataFrames.DataFrame
β Row β x1 β x2 β x3 β
βββββββΌβββββββββββββββββββΌβββββββββββββββββββΌβββββββββββββββββββ€
β 1 β (a = 1, b = 2.0) β (a = 2, b = 4.0) β (a = 3, b = 6.0) β
I replicated the same problem with a new project environment. Iβm using Mac but I doubt the OS plays a role in this issue. Do you have the same package versions as mine?
I donβt know what is happending. Today I run the same command and it throws an error
using Pandas
df=read_csv("iris.csv");
@show typeof(df)
Pandas.DataFrame
using DataFrames,Data
df1=DataFrames.DataFrame(df);
typeof(df1)
MethodError: no method matching DataFrames.DataFrame(::Pandas.DataFrame)
Closest candidates are:
DataFrames.DataFrame(::Any, !Matched::DataStreams.Data.Schema, !Matched::Type{S}, !Matched::Bool; reference) where S at C:\Users\chatura\.julia\packages\DataFrames\utxEh\src\abstractdataframe\io.jl:295
DataFrames.DataFrame(!Matched::Array{Any,1}, !Matched::DataFrames.Index) at C:\Users\chatura\.julia\packages\DataFrames\utxEh\src\dataframe\dataframe.jl:87
DataFrames.DataFrame(; kwargs...) at C:\Users\chatura\.julia\packages\DataFrames\utxEh\src\dataframe\dataframe.jl:142
...
Stacktrace:
[1] top-level scope at In[4]:2
using DataFrames, HTTP, Pandas
const URL = "https://api.bitfinex.com/v1"
function symbols()
r = HTTP.get("$URL/symbols")
s = String(r.body)
return Pandas.read_json(s) # Creates a Pandas.DataFrame.
end
df = symbols()
df2 = DataFrames.DataFrame(df) # This will fail.
I am highlighting a separate connected issue. I am using Julia to read HDF file created in Python. Then I convert it to a Pandas DataFrame which seems to work fine. Subsequently I try to convert this to DataFrames.DataFrame (which I cannot do directly from Python), and the output I get is all messed up.
I am using Julia 1.0 and list of package version is given below.
The discussion here is from Pandas, meaning Pandas.jl, to DataFrame. I actually have a Python pandas dataframe, and suppose support for it needs to be added to IterableTables.jl for it too? Or should such conversion be in Pandas.jl or is already? I guess long term, I should get rid of all Python code (Iβm porting, in phases).
julia> using IterableTables
julia> p_df = DataFrame(py"df_SA")
ERROR: ArgumentError: 'PyObject' iterates 'String' values, which doesn't satisfy the Tables.jl `AbstractRow` interface
Stacktrace:
[1] invalidtable(::PyObject, ::String) at /home/pharaldsson_sym/.julia/packages/Tables/okt7x/src/tofromdatavalues.jl:42
[2] iterate at /home/pharaldsson_sym/.julia/packages/Tables/okt7x/src/tofromdatavalues.jl:48 [inlined]
[3] buildcolumns at /home/pharaldsson_sym/.julia/packages/Tables/okt7x/src/fallbacks.jl:185 [inlined]
[4] columns at /home/pharaldsson_sym/.julia/packages/Tables/okt7x/src/fallbacks.jl:237 [inlined]
[5] DataFrame(::PyObject; copycols::Bool) at /home/pharaldsson_sym/.julia/packages/DataFrames/S3ZFo/src/other/tables.jl:40
[6] DataFrame(::PyObject) at /home/pharaldsson_sym/.julia/packages/DataFrames/S3ZFo/src/other/tables.jl:31
[7] top-level scope at /home/pharaldsson_sym/.julia/packages/PyCall/zqDXB/src/pyeval.jl:232
I also have similar requirement. And, I wonder there is no supported function to read parquet file in Pandas.jl such as read_parquet(). Hence, I was reading the parquet file from python pandas library and couldnβt able to convert to Julia DataFrame.
Any suggestions/updatates?
For anyone coming here from google to convert Pandas dataframes to DataFrames.DataFrame, this post from another thread contains a function which can do this.