0

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())
bbartling
  • 3,288
  • 9
  • 43
  • 88
  • check function to_csv from pandas https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_csv.html.... – Colonel Beauvel Aug 02 '17 at 15:32
  • 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 `ffill`ed – redacted Aug 02 '17 at 15:34
  • 1
    @RobinNemeth if you have `NaN` in the first few rows then `ffill` won't replace these, this is what `bfill` will do – EdChum Aug 02 '17 at 15:37
  • 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 Aug 02 '17 at 15:54

1 Answers1

0

You can use the following piece of code:

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