Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

pandas error:None of ['b_id'] are in the columns

I’m trying to create a dataframe from the following code:

import pandas as pd
from io import StringIO

df = """
 b_id          Rejected                   Remediation                        user
 366           NaN                        38 days 22:05:06.807430            Test
 367           0 days 00:00:05.285239     NaN                                Test
 368           NaN                        NaN                                Test
 371           NaN                        NaN                                Test
 378           NaN                        451 days 14:59:28.830482           Test
 384           28 days 21:05:16.141263    0 days 00:00:44.999706             Test

"""
df= pd.read_csv(StringIO(df.strip()), sep='|')
df.set_index("b_id", inplace = True)

But I received error:

"None of ['b_id'] are in the columns"

Any friends can help ?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Change your separator in read_csv, here \s\s+ (2 or more spaces) seems appropriate:

df= pd.read_csv(StringIO(df.strip()), sep='\s\s+', engine='python')
df.set_index("b_id", inplace = True)

Output:

                     Rejected               Remediation  user
b_id                                                         
366                       NaN   38 days 22:05:06.807430  Test
367    0 days 00:00:05.285239                       NaN  Test
368                       NaN                       NaN  Test
371                       NaN                       NaN  Test
378                       NaN  451 days 14:59:28.830482  Test
384   28 days 21:05:16.141263    0 days 00:00:44.999706  Test
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading