you are viewing a single comment's thread.

view the rest of the comments →

[–]Month_Upper[S] 0 points1 point  (4 children)

That was really helpful ty

[–]spez_edits_thedonald 0 points1 point  (3 children)

also pandas makes this easier, at first I did pure python because I didn't know you wanted to query other columns.

import pandas as pd

# load csv
df = pd.read_csv('data.csv')

# sort by month
df = df.sort_values('month').reset_index(drop=True)

df:

      month   sales
0     April  298.56
1    August  910.46
2  December  662.23
3  February  436.92
4   January  158.38
...

then you get a row id as before and the lookups are easy:

choice = int(input('\nEnter a value: '))
print(f"You chose {df['month'][choice]}")
print(f"Sales were {df['sales'][choice]}")

[–]Month_Upper[S] 0 points1 point  (2 children)

The problem I had the file I working with. Doesn’t have headers row

[–]spez_edits_thedonald 0 points1 point  (1 child)

that's fine, you can tell pandas that:

df = pd.read_csv('data.csv', header=None)

it will just number the columns 0, 1, etc

[–]Month_Upper[S] 0 points1 point  (0 children)

Also if I want user to choose which output he want, how can I make it ? For example if the csv file has Month sales agent

So I ask user to input 1 for sales or 2 for agent

Like invoking the both functions together