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=';')
更多回答
我是一名优秀的程序员,十分优秀!