I want to plot a graph like this with multiple lines
I have multiple csv files
file1.csv
- round sales
- 1 19
- 2 21
- 3 24
- 4 56
- 5 39
file2.csv
- round sales
- 1 21
- 2 31
- 3 41
- 4 21
- 5 23
i tried but i am only able to merge it to one cvs file
df1 = pd.read_csv("z:/python/1.csv")
df2 = pd.read_csv("z:/python/2.csv")
df2 = df2.dropna(axis=1)
merged = df1.merge(df2, on='sno')
merged.to_csv("output.csv", index=False)
but i am trying to plot through multiple csv files instead of merging first
import matplotlib.pyplot as plt
import pandas as pd
df1 = pd.read_csv("z:/python/file1.csv")
df2 = pd.read_csv("z:/python/file2.csv")
df3 = pd.read_csv("z:/python/file3.csv")
df4 = pd.read_csv("z:/python/file4.csv")
ax = df1.plot(label='df1')
df2.plot(ax=ax)
plt.show()
this is plotting 4 lines on graph.. i only need to plot sales for every round.. i dont want to plot line for round can anyone help
try accessing the variable df with the key ['sales'], the read_csv() function returns a dict of all columns, try the following:
df1 = pd.read_csv("z:/python/file1.csv")['sales']
replace the following line in your code:
ax = df1.plot(label='df1')
with the following:
ax = df1.plot(label='year-xxxx', x="round", y="sales")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.