我正在开发一个读取csv文件并为每一列创建一个列表的软件。
在我的程序中之后,我将在X坐标上使用DataTime
并在Y坐标上使用S1;S2;S3...
绘制这些数据
我的csv文件:
DateTime;S1;S2;S3
2020-07-16 15:11:34.358231;677.0552427707063;787.6245155900142;543.0755073183745
2020-07-16 15:11:34.360247;535.4790551706492;317.65859520197984;218.64223032216418
2020-07-16 15:11:34.362263;451.9436928722545;449.5560971162404;215.33038976545765
2020-07-16 15:11:34.364279;72.31352267938303;251.55939892326035;896.9233907560412
2020-07-16 15:11:34.366295;758.7365312885398;686.7909954314093;303.9852170969752
2020-07-16 15:11:34.368311;593.8244329562257;698.5981983561348;369.11408762777785
2020-07-16 15:11:34.370327;338.56552989499176;469.327619765774;331.0295457896333
2020-07-16 15:11:34.372343;729.3276090259968;690.776181594403;97.6830657885398
2020-07-16 15:11:34.374359;284.58252864976197;569.0028638781417;196.02767689983673
2020-07-16 15:11:34.376375;909.5920826056772;178.28447193362686;240.4015082916274
我想按列读取文件,但是此文件可以更改列数,因为Signals是变量。例如,我可以拥有S1;S2;S3;S4;S5...
因此,我希望能够独立读取各列,我有多少列。
DateTime
列是标准列,因此我可以阅读1次。
这是我的实际代码:
import pandas as pd
from datetime import datetime
from csv import reader
class Read_csv:
def csv_reader(self, file_name):
with open(file_name, 'r') as read_obj:
csv_reader = reader(read_obj)
csv_header = next(csv_reader)
df = pd.read_csv(file_name, delimiter = ';')
self.datetime_array = list(map(lambda x: datetime.strptime(x, '%Y-%m-%d %H:%M:%S.%f'), df["DateTime"]))
for i in range((len(csv_header)-1)):
#TODO:read signals columns
我更新的代码:
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
class Read_csv:
def csv_reader(self, file_name):
df = pd.read_csv(file_name, delimiter = ';', parse_dates=['DateTime']).set_index('DateTime')
df.plot()
sns.lineplot(data=df)
plt.savefig("Signals_Chart.png")
答案 0 :(得分:2)
sns.lineplot(data=df, dashes=False)
plt.legend(bbox_to_anchor=(1.04, 0.5), loc="center left", borderaxespad=0)
test.csv
# read in the file
df = pd.read_csv('test.csv', delimiter = ';', parse_dates=['DateTime']).set_index('DateTime')
# plot the file
sns.lineplot(data=df)
的文件中 <entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
<parameters>
<parameter value="<My Connection String>" />
</parameters>
</defaultConnectionFactory>
</entityFramework>