# Pandas pct\_change

**URL:** <https://forum.freecodecamp.org/t/pandas-pct-change/372437>\
**Category:** General\
**Created:** [April 13, 2020, 12:03pm UTC](https://forum.freecodecamp.org/t/pandas-pct-change/372437 "2020-04-13T12:03:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![react](https://avatars.discourse-cdn.com/v4/letter/r/ecccb3/32.png) [@react](https://forum.freecodecamp.org/u/react)\
**Post date:** [April 13, 2020, 12:03pm UTC](https://forum.freecodecamp.org/t/pandas-pct-change/372437/1 "2020-04-13T12:03:30Z")

</div>

Hello,

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

```auto
prices = prices.loc[(prices!=0).all(1)]
prices_percentage_change = prices.apply(lambda x: x.pct_change(axis=1) if x.name 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'>`

---

<div class="post-metadata">

**Author:** ![JeremyLT](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jeremylt/32/291894_2.png) [@JeremyLT](https://forum.freecodecamp.org/u/JeremyLT)\
**Post date:** [April 13, 2020, 1:52pm UTC](https://forum.freecodecamp.org/t/pandas-pct-change/372437/2 "2020-04-13T13:52:08Z")

</div>

We’ll need to see more to help.

---

<div class="post-metadata">

**Author:** ![react](https://avatars.discourse-cdn.com/v4/letter/r/ecccb3/32.png) [@react](https://forum.freecodecamp.org/u/react)\
**Post date:** [April 13, 2020, 3:17pm UTC](https://forum.freecodecamp.org/t/pandas-pct-change/372437/3 "2020-04-13T15:17:37Z")

</div>

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.

```auto
  constructor(props) {
    super(props);
    this.state = {
      aimCompanies: [],
      lseCompanies: [],
      searchQuery: ""
    };
  }

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

```

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

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [June 1, 2021, 6:58pm UTC](https://forum.freecodecamp.org/t/pandas-pct-change/372437/4 "2021-06-01T18:58:47Z")

</div>


