I would like to create a graph on filtered data from a csv. A graph is created but without content.
Here is the code and the result:
code cell 1
# var 4 graph
xs = []
ys = []
name = "Anna"
gender = "F"
state = "CA"
# 4 reading csv file
import pandas as pd
# reading csv file
dataFrame = pd.read_csv("../Kursmaterialien/data/names.csv")
#print("DataFrame...\n",dataFrame)
# select rows containing text
dataFrame = dataFrame[(dataFrame['Name'] == name)&dataFrame['State'].str.contains(state)&dataFrame['Gender'].str.contains(gender)]
#print("\nFetching rows with text ...\n",dataFrame)
print(dataFrame)
# append var with value
xs.append(list(dataFrame['Year']))
ys.append(list(dataFrame['Count']))
#xs.append(list(map(str,dataFrame['Year'])))
#ys.append(list(map(str,dataFrame['Count'])))
print(xs)
print(ys)
result cell 1
code cell 2
%matplotlib inline
import matplotlib.pyplot as plt
plt.plot(xs,ys)
plt.show()
result cell 2
I see that the variables start with two brackets, but don't know if that is the problem and how to fix it.
The graphic should look something like this:
source https://stackoverflow.com/questions/74915542/phyton-graph-from-csv-filtered-by-pandas-shows-no-graph
Comments
Post a Comment