Multi-question help w/ guided project 5

Hello friends. I’ve been working on this project and have a few technical things I’m stuck on. I’m not done with it yet. And I’m still trying to solve these problems. But I wanted to see if I could get a few things done so I can finish it. Since I have more than one ? and the code is long I just uploaded the notebook. Is this a good idea? (first question I guess) Here are the actual questions, they are commented out in the code as well.

  1. In cell 3 I am still trying to force certain values as xtick labels. I am using fig ax for the first time and I can manipulate them some but not just pick. For this graph I would like ticks = [2000,2005,2010,2015,2020]. Adam had some suggestions but I couldn’t make any work.

  2. Please share your thoughts on the functions in cells 5 & 6. I initially built xchange but thought incorporating the rolling mean in the main data frame might be handy. So I built a new df and framer.

  3. Is there a way I can apply either function to all 42 columns? I have struggled with this more than anything else in this project I think. Tonight I am trying to use a for loop to make 42 new dfs using a master currency list.

  4. In cell 7 I have to make a new list of currencies to use in the loop for the figure. I tried so many ways to use the list I built in the function but I can’t separate the title of the df from it’s contents. So to put it another way, I cant stringify the name of the df.

  5. Also in cell 7 I want to use the variable for each loop to create the y label. I can make it the same string for each axes, but not unique to each.

That’s it for now. Thanks ahead of time. I have been really trying to put it all together on this one.

Here’s the notebook in a new tab. :slight_smile:

The Euro on Forex.ipynb (618.7 KB)

  1. I’ve removed a few lines and added 2:
# create a us dollar to euro dataframe and add 30 day rolling mean column
us_dollar = x_rates[["date","us_dollar"]].copy()
us_dollar["rolling_mean_30"] = us_dollar["us_dollar"].rolling(30).mean()

# line graph for dollar to euro exchange rate
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
%matplotlib inline

fig, ax = plt.subplots(figsize=(10,3.75))
ax.plot(us_dollar["date"], us_dollar["rolling_mean_30"])

       ylabel="US dollar",
       title="US Dollar to Euro Exhcange Rates")
# specify datetime xticks:
ax.set_xticks(  ['2000-01-04 00:00:00','2005-01-04 00:00:00','2010-01-04 00:00:00','2015-01-04 00:00:00','2020-01-04 00:00:00'])
# labels
ax.set_xticklabels( [2000,2005,2010,2015,2020])
1 Like

I put this using Jupyter locally and it worked. Thanks! I had tried a lot of things similar to this but had definitely not known about using the extended format '2000-01-04 00:00:00' for the entries in the "date" column.

And then I think the help you gave me on the other question re: data frames and loops is going to make me restructure the project a little. Thanks again.