Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9172793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:26:08+00:00 2026-06-17T16:26:08+00:00

Column y below should be [‘Reg’, ‘Reg’, ‘Swp’, ‘Swp’] In [1]: pd.read_csv(‘/tmp/test3.csv’) Out[1]: x,y

  • 0

Column y below should be [‘Reg’, ‘Reg’, ‘Swp’, ‘Swp’]

In [1]: pd.read_csv('/tmp/test3.csv')  
Out[1]:  
x,y  
 ^@^@^@,Reg  
 ^@^@^@,Reg  
I,Swp  
I,Swp  

In [2]: ! cat /tmp/test3.csv  
     x    y  
0  
1  NaN  NaN  
2    I  Swp  
3    I  Swp    

In [3]: f = open('/tmp/test3.csv', 'rb'); print(repr(f.read()))  
'x,y\n \x00\x00\x00,Reg\n \x00\x00\x00,Reg\nI,Swp\nI,Swp\n'
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T16:26:10+00:00Added an answer on June 17, 2026 at 4:26 pm

    Yes, I could reproduce the problem, but don’t know how to fix it with pd.read_csv. Here is a workaround:

    In [46]: import numpy as np
    In [47]: arr = np.genfromtxt('test3.csv', delimiter = ',', 
                                 dtype = None, names = True)
    
    In [48]: df = pd.DataFrame(arr)
    
    In [49]: df
    Out[49]: 
       x    y
    0     Reg
    1     Reg
    2  I  Swp
    3  I  Swp
    

    Note that with names = True the first valid line of the csv is interpreted as column names (and therefore does not affect the dtype of the values on the subsequent lines.) Thus, if the csv file contains numerical data such as

    In [22]: with open('/tmp/test.csv','r') as f:
       ....:     print(repr(f.read()))
       ....:     
    'x,y,z\n \x00\x00\x00,Reg,1\n \x00\x00\x00,Reg,2\nI,Swp,3\nI,Swp,4\n'
    

    Then genfromtxt will assign a numerical dtype to the third column (<i4 in this case).

    In [19]: arr = np.genfromtxt('/tmp/test.csv', delimiter = ',', dtype = None, names = True)
    
    In [20]: arr
    Out[20]: 
    array([('', 'Reg', 1), ('', 'Reg', 2), ('I', 'Swp', 3), ('I', 'Swp', 4)], 
          dtype=[('x', '|S3'), ('y', '|S3'), ('z', '<i4')])
    

    However, if the numerical data is intermingled with bytes such as '\x00' then genfromtxt will be unable to recognize this column as numerical and will therefore resort to assigning a string dtype. Nevertheless, you can force the dtype of the columns by manually assigning the dtype parameter. For example,

    In [11]: arr = np.genfromtxt('/tmp/test.csv', delimiter = ',', dtype = [('x', '|i4'), ('y', '|S3')], names = True)
    

    sets the first column x to have dtype |i4 (4-byte integers) and the second column y to have dtype |S3 (3-byte string). See this doc page for more information on available dtypes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a trigger on one table which should update date_modified column. Is below
As far as I know to make a column unique the structure below should
I have an a new table with the column below: id , name ,
I have the below column on my table what gets binded on pageload, the
Take a simple table like below: Column Headings: || Agent's Name || Time Logged
I have a table structure having a EMP_DATE column as below ID EMP_DATE ----
I'm trying to display IEnumerable int values in JQGrid. As seen below column gmu
I'm using sortable as below : $('.column').sortable({ connectWith: #column1, revert: 100, items: .myItems:not(.excluded), }).disableSelection();
Below are the contents of sid column in a table ( where S05201215 is
The code below is giving me the error: column 'id' in field list is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.