You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/06/12 08:57:26 UTC

[GitHub] [arrow] ni-todo-spot commented on issue #13353: Casting a decimal column of a table into a float type when converting a table into a pandas dataframe

ni-todo-spot commented on issue #13353:
URL: https://github.com/apache/arrow/issues/13353#issuecomment-1153106500

   @westonpace Thanks for your reply!
   I think using your answer I can implement a solution which is good enough (adding it here in case someone might find it useful):
   
   ```python
   
   import pandas as pd
   import pyarrow as pa
   import pyarrow.compute as pac
   
   table = ... # contains a decimal column
   for i, (col_name, type_) in enumerate(zip(table.schema.names, table.schema.types)):
       if pa.types.is_decimal(type_):
           table = table.set_column(i, col_name, pac.cast(table.column(col_name), pa.float64()))
   df = table.to_pandas()
   ```
   
   Thanks a lot!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org