0
votes

Hello I have a pandas series dataframe name "BoilerInfo" from an API request, and I would like to create a CSV file of the data. How do I do that?

Can python create a CSV file in this directory? C:\Users\lingbart\Documents\Python\WB Data

#Create Dataframe for the supply & return temp. Use ffill to merge missing data to do math
BoilerInfo = pd.DataFrame({'hws' : hws_df, 'hwr' : hwr_df,
                        'DP' : hotWaterLoopDP_df, 'pump3O' : pump3O_df,
                        'oat' : oat_df, 'elecMeter' : elecMeter_df,
                       'gasMeter' : gasMeter_df})
BoilerInfo = BoilerInfo.fillna(method = 'ffill').fillna(method = 'bfill')

#Show statistics
print(BoilerInfo.describe())
print(BoilerInfo.head())
print(BoilerInfo.tail())
1
check function to_csv from pandas pandas.pydata.org/pandas-docs/stable/generated/…....Colonel Beauvel
btw: does this piece of code BoilerInfo = BoilerInfo.fillna(method = 'ffill').fillna(method = 'bfill') really accomplish anything? To me the 'bfill' seems redundand, since at that point everything is ffilledredacted
@RobinNemeth if you have NaN in the first few rows then ffill won't replace these, this is what bfill will doEdChum
Can you give me a tip on how I can write the ffill and bfill better? Newby here for python and I copied this from a different script because do I get a lot of NaN's in the data coming back... It fixes the issue, but I would not know if its redundant or not. Thanks!bbartling

1 Answers

0
votes

You can use the following piece of code:

df.to_csv('C:/Users/lingbart/Documents/Python/WB Data/fileName.csv, sep=',')