gpt4 book ai didi

How to import a csv file as a table and not as a semicolons (;) separating columns values?(如何将CSV文件作为表格导入,而不是以分号(;)分隔列值?)

转载 作者:bug小助手 更新时间:2023-10-24 22:24:08 25 4
gpt4 key购买 nike



When I use this code:

当我使用此代码时:


import pandas as pd
df = pd.read_csv("path.csv")
df

it imports the csv file, but the columns are separated with semicolons (;) instead of bars (|). Example:

它导入CSV文件,但列之间用分号(;)而不是条(|)分隔。示例:


first Name;full name;age;salary
jack;Adams;26;2500$

This is what it looks like in Jupyter Notebook. I don't know how to import the file as a table with bars.

这就是Jupyter Notebook中的内容。我不知道如何将文件导入为带条的表格。


更多回答

Use the optional sep argument to read_csv() to tell it what character to use as the field separator.

使用可选的sep参数来读取_csv(),以告诉它使用哪个字符作为字段分隔符。

Use pd.read_csv("path.csv", sep=";").

使用pd.read_csv(“path.csv”,sep=“;”)。

it worked, im so grateful for your help.

成功了,我真的很感激你的帮助。

优秀答案推荐

Your csv file is probably separated by semicolons and not commas, which is why your output looks that way.

Pandas' read_csv() by default separates by commas, but you can specify the separator:

您的CSV文件可能由分号而不是逗号分隔,这就是您的输出看起来是这样的原因。默认情况下,熊猫的Read_csv()以逗号分隔,但您可以指定分隔符:


df = pd.read_csv("path.csv", sep=';')

更多回答

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com