import pandas as pd
import matplotlib.pyplot as plt
# Load your dataset into a Pandas DataFrame
df = pd.read_csv('GOVSTIMESERIES.GS00EP02-2023-04-07T200530.csv')
# Get a list of unique department labels
department_labels = df['AGG_DESC_LABEL'].unique()
# Ask the user to select a department label
selected_department = input('Enter the department label you want to plot: ')
# Filter the DataFrame to only include the selected department
df_selected = df[df['AGG_DESC_LABEL'] == selected_department]
# Create a plot of FT_pay over years
plt.plot(df_selected['YEAR'], df_selected['FT_PAY'])
# Add labels and title to the plot
plt.xlabel('Year')
plt.ylabel('FT_pay')
plt.title(f'{selected_department} FT_pay over Years')
# Display the plot
plt.show()
Enter the department label you want to plot: Financial Administration
import pandas as pd
import matplotlib.pyplot as plt
# read the dataset into a pandas dataframe
df = pd.read_csv('GOVSTIMESERIES.GS00EP02-2023-04-07T200530.csv')
# get user input for the year
year = input("Enter a year: ")
# filter the dataframe to only include the specified year
df_filtered = df[df['YEAR'] == int(year)]
# remove commas from the FT_EMP column and convert it to float
df_filtered['FT_EMP'] = df_filtered['FT_EMP'].str.replace(',', '').astype(float)
# group the data by department and sum the FT_EMP column
grouped_data = df_filtered.groupby('AGG_DESC_LABEL')['FT_EMP'].sum()
# create a pie chart using the grouped data and adjust label font size
plt.pie(grouped_data.values, labels=grouped_data.index, autopct='%1.1f%%', labeldistance=1.2,
wedgeprops={'edgecolor': 'white', 'linewidth': 1}, textprops={'fontsize': 6})
plt.title(f"Department-wise FT_EMP distribution for {year}")
plt.rcParams['figure.figsize'] = [10, 10]
plt.show()
Enter a year: 2021
<ipython-input-42-22d030090082>:14: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy df_filtered['FT_EMP'] = df_filtered['FT_EMP'].str.replace(',', '').astype(float)