-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG:Characters like '/' are being replaced by '_' when importing a CSV file into Python with pandas. #58257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Can you provide a minimal bug report ? |
take |
Hey! I'm not able to reproduce this issue - I'm able to use read_csv and to_csv with no issues with / characters in columns. Follow up if the issue persists, or maybe provide the specific file that caused the error! |
Hi @harishvspeaker, I've tried reproducing the bug using the test case you described, but the code appears to work as expected. Here's the test case I used: import pandas as pd
import io
def test_slash_character_replacement():
# Create a sample CSV content with a string containing '/'
csv_content = """column1,column2
value1,he/him
value2,she/her"""
# Use io.StringIO to simulate reading from a file
csv_file = io.StringIO(csv_content)
# Read the CSV file using pandas read_csv
df = pd.read_csv(csv_file)
# Check if the '/' character is retained in the DataFrame
assert df.loc[0, 'column2'] == 'he/him', "Expected '/' character in the data"
assert df.loc[1, 'column2'] == 'she/her', "Expected '/' character in the data"
# Optionally, save the DataFrame back to CSV and check the content
# with io.StringIO to avoid file I/O
output_csv = io.StringIO()
df.to_csv(output_csv, index=False)
output_csv.seek(0)
saved_csv_content = output_csv.read()
print(saved_csv_content)
# Verify that the saved CSV content retains the original '/' character
assert 'he/him' in saved_csv_content, "Expected '/' character in saved CSV content"
assert 'she/her' in saved_csv_content, "Expected '/' character in saved CSV content"
# Run the test function
test_slash_character_replacement() Output
The '/' character is retained in both the DataFrame and the saved CSV content. Could you please provide a specific test case or CSV file where you are seeing the bug? This would help us understand the issue better and work on a fix. Thank you! |
Hi @harishvspeaker I have been working on investigating the bug you described, but unfortunately, I have not been able to reproduce the problem. Could you please share the test case and more detailed steps on how we can produce the bug? Specific information such as data inputs, environment details (e.g., OS version, browser, etc.), and any other pertinent information will be helpful for me or the open source team to better understand and resolve the issue. If you are unable to provide additional details or if the issue is no longer relevant, please close the issue. |
Closing as it seems like there's no reproducible example |
Pandas version checks
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Issue Description
say i have a string row "he/him" when loaded into python it automatically gets converted into "he_him" and when the same data frame is saved back into a csv format "_" is retained
Expected Behavior
/...
Installed Versions
Replace this line with the output of pd.show_versions()
The text was updated successfully, but these errors were encountered: