0

i created a data frame using polars. when datas are inserted, dtype of the coulmn automatically changes to what inserted. (i think its a feature of polars?) but how do you change the dtype of speicfic table? for example "name" has f32 by default when theres no data but i want "name" to have utf8 or string even when theres no data. so i can make IF condition to find datas by name or w/e.

┌──────┬──────┬──────┬──────┬────────────┬───────┬──────┐
│ xmin ┆ ymin ┆ xmax ┆ ymax ┆ confidence ┆ class ┆ name │
│ ---  ┆ ---  ┆ ---  ┆ ---  ┆ ---        ┆ ---   ┆ ---  │
│ f32  ┆ f32  ┆ f32  ┆ f32  ┆ f32        ┆ f32   ┆ f32  │
╞══════╪══════╪══════╪══════╪════════════╪═══════╪══════╡
└──────┴──────┴──────┴──────┴────────────┴───────┴──────┘
# what i wanna do 
if boxes[(boxes['name']=='star')]: 
    blah blah blah

# above code gives me an error 
ValueError: could not convert string to float: 'star'




 
wookidookik123
  • 79
  • 2
  • 10
  • 1
    The answer here will help you: https://stackoverflow.com/questions/71790235/polars-switching-between-dtypes-within-a-dataframe –  May 07 '22 at 15:25

0 Answers0