Pandas pct_change


I’m trying to apply pct_change to only the numerical columns in a dataframe (because it errors, I assume when dealing with strings).

prices = prices.loc[(prices!=0).all(1)]
prices_percentage_change = prices.apply(lambda x: x.pct_change(axis=1) if not in ['name', 'cid', 'symbol'] else x)

It works if axis=0, i.e. calculates between rows but the above gives:

ValueError: No axis named 1 for object type <class 'pandas.core.series.Series'>

We’ll need to see more to help.

Thanks, I think the answer is to use list comprehension to make sure it goes through each column, so you aren’t using a Series. I just did a work around in the end.

I exported the df as json, now I’m trying to use it in a React frontend app but I’m have trouble reading in the data.

  constructor(props) {
    this.state = {
      aimCompanies: [],
      lseCompanies: [],
      searchQuery: ""

  componentDidMount = () => {
    fetch("../lse_prices_df.json").then(lseCompanies =>
      this.setState({ lseCompanies })

It doesn’t error but this.state.lseCompanies is an empty array when I debug