react
April 13, 2020, 12:03pm
1
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).
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'>
We’ll need to see more to help.
react
April 13, 2020, 3:17pm
3
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) {
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