我想使用pandas导入一个csv文件作为 Dataframe 。该文件的结构如屏幕截图所示。(https://i.stack.imgur.com/N91d7.png)然而,由于某些原因,使用
df = pd.read_csv("Test.csv", delimiter = ',')
不起作用。生成的dataframe在一个单独的列中包含所有内容。
如何正确地分隔列?提前感谢。
我已经尝试了不同的“read_csv”提示符选项,但是,我还没有找到解决方案。
我想使用pandas导入一个csv文件作为 Dataframe 。该文件的结构如屏幕截图所示。(https://i.stack.imgur.com/N91d7.png)然而,由于某些原因,使用
df = pd.read_csv("Test.csv", delimiter = ',')
不起作用。生成的dataframe在一个单独的列中包含所有内容。
如何正确地分隔列?提前感谢。
我已经尝试了不同的“read_csv”提示符选项,但是,我还没有找到解决方案。
2条答案
按热度按时间zhte4eai1#
我不确定你是怎么得到一个逗号不明确的csv文件的(值是不带引号的,并且包含逗号,分隔符也是逗号),但好消息是…
假设整个文件都遵循您问题中的格式(特别是,如果每隔一列为空),这应该可以实现您想要的功能:
样品输入:
输出:
转置输出(更易于阅读):
请注意,为了便于创建示例,我使用了string和StringIO类而不是文本文件。
jaql4c8m2#
用途: