votes up 4

feather must have string column names

Package:
pandas
github stars 30911
Exception Class:
ValueError

Raise code

)

    # validate columns
    # ----------------

    # must have value column names (strings only)
    if df.columns.inferred_type not in valid_types:
        raise ValueError("feather must have string column names")

    with get_handle(
        path, "wb", storage_options=storage_options, is_text=False
    ) as handles:
        feather.write_feather(df, handles.handle, **kwargs)
😲  Walkingbet is Android app that pays you real bitcoins for a walking. Withdrawable real money bonus is available now, hurry up! 🚶

Ways to fix

votes up 1 votes down

DataFrame.to_feather doesn't support columns that are not string.

Reproducing the error:

pipenv install pandas

import pandas as pd
df1 = pd.DataFrame([['a''b'], ['c''d']],
                   columns=[1122])
df1.to_feather("path")
print(df1)

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-9-8ad350f59000> in <module>()
      2 df1 = pd.DataFrame([['a', 'b'], ['c', 'd']],
      3                    columns=[11, 22])
----> 4 df1.to_feather("path")
      5 print(df1)

/usr/local/lib/python3.7/dist-packages/pandas/util/_decorators.py in wrapper(*args, **kwargs)
    197                 else:
    198                     kwargs[new_arg_name] = new_arg_value
--> 199             return func(*args, **kwargs)
    200 
    201         return cast(F, wrapper)

/usr/local/lib/python3.7/dist-packages/pandas/core/frame.py in to_feather(self, path, **kwargs)
   2213         from pandas.io.feather_format import to_feather
   2214 
-> 2215         to_feather(self, path, **kwargs)
   2216 
   2217     @doc(

/usr/local/lib/python3.7/dist-packages/pandas/io/feather_format.py in to_feather(df, path, **kwargs)
     60     # must have value column names (strings only)
     61     if df.columns.inferred_type not in valid_types:
---> 62         raise ValueError("feather must have string column names")
     63 
     64     feather.write_feather(df, path, **kwargs)

ValueError: feather must have string column names

Fixed:

import pandas as pd
df1 = pd.DataFrame([['a''b'], ['c''d']],
                   columns=["11""22"])
df1.to_feather("path")
print(df1)

 11 22
0  a  b
1  c  d

Aug 14, 2021 kellemnegasi answer
kellemnegasi 31.6k

Add a possible fix

Please authorize to post fix