[英]Splitting data from .csv file and plotting graph
I have a question where I have a .csv file like this: 我有一个问题,我有一个像这样的.csv文件:
Name1
x1,y1
x2,y3
x3,y3
.
.
x100,y100
Name2
x1,z1
x2,z2
x3,z3
.
.
x100,z100
Name3
...
...
Name10
...
...
Is there any ways I can split this data in pandas so I can plot graph with it. 有什么方法可以在熊猫中分割这些数据,这样我就可以用它绘制图形。
Label will be Name1,Name2... 标签将是Name1,Name2 ......
Not sure what your graph needs to look like but here is one way to load your csv file into a pandas dataframe: 不确定你的图形需要什么样子,但这里有一种方法可以将你的csv文件加载到pandas数据帧中:
import pandas
# declarations
data = []
data_dict = {}
with open('file.csv', 'r') as f:
while True:
csv_line = f.readline()
if not csv_line:
break
split_text = csv_line.replace('\n', '').split(',')
if len(split_text) == 1 and split_text != ['']:
header = split_text[0]
data = []
data_dict.update({header: data})
elif len(split_text) == 2:
data += split_text
df = pandas.DataFrame(data_dict)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.