pandas

fill in dates and use previous values

醉酒当歌 提交于 2021-02-10 16:43:13
问题 my pandas dataframe looks like the below country date gd US 01-01-2014 2 US 01-01-2015 3 US 01-01-2013 0.4 UK 01-01-2000 0.7 UK 02-01-2001 0.5 UK 01-01-2016 1 what I want to do is : 1) Fill all dates (daily) starting from each countries minimum date so say for US it is 01-01-2013 upto today and for UK it is 01-01-2000 daily upto today. 2) Fill gd column with previous available data many thanks for your help 回答1: In [67]: today = pd.to_datetime(pd.datetime.now()).normalize() In [68]: l = df

Remove “days 00:00:00”from dataframe [duplicate]

杀马特。学长 韩版系。学妹 提交于 2021-02-10 16:42:30
问题 This question already has answers here : Pandas Timedelta in Days (5 answers) Closed 1 year ago . So, I have a pandas dataframe with a lot of variables including start/end date of loans. I subtract these two in order to get their difference in days. The result I get is of the type i.e. 349 days 00:00:00. How can I keep only for example the number 349 from this column? 回答1: Check this format, df['date'] = pd.to_timedelta(df['date'], errors='coerce').days also, check .normalize() function in

How can I cleanly normalize data and then “unnormalize” it later?

匆匆过客 提交于 2021-02-10 16:21:07
问题 I am using Anaconda with a Tensorflow neural network. Most of my data is stored with pandas . I am attempting to predict cryptocurrency markets. I am aware that this lots of people are probably doing this and it is most likely not going to be very effective, I'm mostly doing it to familiarize myself with Tensorflow and Anaconda tools. I am fairly new to this, so if I am doing something wrong or suboptimally please let me know. Here is how I aquire and handle the data: Download datasets from

How can I cleanly normalize data and then “unnormalize” it later?

风流意气都作罢 提交于 2021-02-10 16:19:52
问题 I am using Anaconda with a Tensorflow neural network. Most of my data is stored with pandas . I am attempting to predict cryptocurrency markets. I am aware that this lots of people are probably doing this and it is most likely not going to be very effective, I'm mostly doing it to familiarize myself with Tensorflow and Anaconda tools. I am fairly new to this, so if I am doing something wrong or suboptimally please let me know. Here is how I aquire and handle the data: Download datasets from

Seaborn correlation heatmap with equal cell size

夙愿已清 提交于 2021-02-10 16:18:08
问题 I am plotting various correlation matrices with a different number of columns using seaborn. For the sake of eye-candy, I'd like to have all correlation matrices to have the same cell size. Unfortunately, I am not able to parameterize seaborn to do so. Here is a minimal example: from string import ascii_letters import numpy as np import pandas as pd import seaborn as sns import matplotlib.pyplot as plt # Generate two random dataset rs = np.random.RandomState(42) d1 = pd.DataFrame(data=rs

How to write an data array to excel in a row instead of in a column using pandas in Python

北城余情 提交于 2021-02-10 16:06:11
问题 a= [1,2,3,4,5] df=DataFrame(a) .... #setup excelwriter and dataframe df.to_excel(writer, sheet_name=sheetname,startrow=1, startcol=1, header=False, index=False) Output: 1\n 2\n 3\n 4\n 5 How can I get output as: 1 2 3 4 5 回答1: To output in a line use this: df = df.transpose() Full code: #!/usr/bin/python import pandas as pd import xlsxwriter as xlsw a = [1,2,3,4,5] df = pd.DataFrame(a) df = df.transpose() xlsfile = 'pandas_simple.xlsx' writer = pd.ExcelWriter(xlsfile, engine='xlsxwriter') df

How to write an data array to excel in a row instead of in a column using pandas in Python

回眸只為那壹抹淺笑 提交于 2021-02-10 16:02:33
问题 a= [1,2,3,4,5] df=DataFrame(a) .... #setup excelwriter and dataframe df.to_excel(writer, sheet_name=sheetname,startrow=1, startcol=1, header=False, index=False) Output: 1\n 2\n 3\n 4\n 5 How can I get output as: 1 2 3 4 5 回答1: To output in a line use this: df = df.transpose() Full code: #!/usr/bin/python import pandas as pd import xlsxwriter as xlsw a = [1,2,3,4,5] df = pd.DataFrame(a) df = df.transpose() xlsfile = 'pandas_simple.xlsx' writer = pd.ExcelWriter(xlsfile, engine='xlsxwriter') df

How to write an data array to excel in a row instead of in a column using pandas in Python

ε祈祈猫儿з 提交于 2021-02-10 16:02:21
问题 a= [1,2,3,4,5] df=DataFrame(a) .... #setup excelwriter and dataframe df.to_excel(writer, sheet_name=sheetname,startrow=1, startcol=1, header=False, index=False) Output: 1\n 2\n 3\n 4\n 5 How can I get output as: 1 2 3 4 5 回答1: To output in a line use this: df = df.transpose() Full code: #!/usr/bin/python import pandas as pd import xlsxwriter as xlsw a = [1,2,3,4,5] df = pd.DataFrame(a) df = df.transpose() xlsfile = 'pandas_simple.xlsx' writer = pd.ExcelWriter(xlsfile, engine='xlsxwriter') df

How to make an axes occupy multiple subplots when using pandas datetime plot?

感情迁移 提交于 2021-02-10 16:01:19
问题 I would like to create a (sub)plot with two rows and two columns where the plot in the lower row occupies both axes. Since I use the plot from within pandas datetime (I think) I was not able to use this solution. fig, axes = plt.subplots(nrows=2, ncols=2) df1.set_index('Date').plot(ax=axes[0,0]) df2.set_index('Date').plot(ax=axes[0,1]) df3.set_index('Date').plot(ax=axes ??? ) How do I need to assign the axes (if at all possible) in order to get something like this: 回答1: You can do in this way

How to make an axes occupy multiple subplots when using pandas datetime plot?

北慕城南 提交于 2021-02-10 16:00:22
问题 I would like to create a (sub)plot with two rows and two columns where the plot in the lower row occupies both axes. Since I use the plot from within pandas datetime (I think) I was not able to use this solution. fig, axes = plt.subplots(nrows=2, ncols=2) df1.set_index('Date').plot(ax=axes[0,0]) df2.set_index('Date').plot(ax=axes[0,1]) df3.set_index('Date').plot(ax=axes ??? ) How do I need to assign the axes (if at all possible) in order to get something like this: 回答1: You can do in this way