Navigation

    Quantiacs Community

    • Register
    • Login
    • Search
    • Categories
    • News
    • Recent
    • Tags
    • Popular
    • Users
    • Groups

    Pandas and xarray

    Strategy help
    3
    5
    380
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • X
      xiaolan last edited by

      Hi, I am starting to get used to xarray, still I prefer pandas because I know it very well...what is the best recipe for converting data structures from xarray to pandas language?

      support 1 Reply Last reply Reply Quote 1
      • support
        support @xiaolan last edited by

        @xiaolan Hello, the transformation is very simple. Let us suppose that you load the data, and select some field, for example the close, from the native xarray structure using:

        import qnt.data as qndata
        data = qndata.cryptodaily.load_data(min_date="2016-01-01")
        close = data.sel(field="close")
        

        You can convert to pandas using:

        close_pandaized = close.to_pandas()
        

        Then you can work with pandas. Let us come to the final weight, and let us say they are a pandas dataframe. You should convert them to the final xarray data structure using:

        weights = weights_pandaized.unstack().to_xarray()
        
        X 1 Reply Last reply Reply Quote 1
        • X
          xiaolan @support last edited by

          @support Thank you! Yes, this is what I needed, xarray -> pandas -> xarray

          support 1 Reply Last reply Reply Quote 0
          • support
            support @xiaolan last edited by

            @xiaolan Ok, but please note that you can work all the time with xarray, the documentation is very good:

            http://xarray.pydata.org/en/stable/

            1 Reply Last reply Reply Quote 0
            • A
              aluminum.pig Banned last edited by

              This post is deleted!
              1 Reply Last reply Reply Quote 0
              • First post
                Last post
              Powered by NodeBB | Contributors
              • Documentation
              • About
              • Career
              • My account
              • Privacy policy
              • Terms and Conditions
              • Cookies policy
              Home
              Copyright © 2014 - 2021 Quantiacs LLC.
              Powered by NodeBB | Contributors