#π i'm trying to analyze why there was a jump in tortilla prices for mom and pop stores from 2019-202
30 messages Β· Page 1 of 1 (latest)
@small nacelle
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
i was able to get a year column from the df2
(the second csv)
i just don't understand how i'm supposed to combine them?
a merge would work
but is a merge what would be most useful?
So what I would do is make a new dataframe with the data you care about from dataframe1. And then do the same for dataframe2. And then you can concat the two new dataframes as they will have the same columns filled with the data you care about.
brb, hiking. π
hmmmm
so just subset data from df1?
what's wrong with just concatenating it all together since i don't know what i'm looking for quite yet?
is it bc it's super computationally intensive?
i don't quite understand
this is the plot that triggered my curiosity
i want to compare the price of the tortilla to other goods
for the years 2019 to 2022
even all the way back since 2007 is fine
but the main focus is 2019-2022
i'm stuck as hell
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
import matplotlib.ticker as mticker
df = pd.read_csv("/Users/rahuldas/Desktop/Tortilla Dataset/tortilla_prices.csv")
print(df.head)
print(df.info())
print(df.shape)
print(df.columns)
print(df.dtypes)
print("hello world")
price_per_kilogram_missing = df["Price per kilogram"].isna().sum()
print(price_per_kilogram_missing)
price_per_kilogram_missing_mean = df["Price per kilogram"].mean()
print(price_per_kilogram_missing_mean)
df["Price per kilogram"] = df["Price per kilogram"].fillna(price_per_kilogram_missing_mean)
print(df["Price per kilogram"].isna().sum())
sns.set_style("whitegrid")
sns.kdeplot(data=df, x="Price per kilogram", hue="Store type", fill=True)
#plt.show()
fig, ax = plt.subplots(figsize=(6, 6))
# drawing the plot
sns.boxplot(data=df, x = "Store type", y = "Price per kilogram", color = "lightblue", ax=ax);
plt.xticks(rotation=90)
sns.despine(left=True, right=True, top=True, bottom=True)
plt.show()
ax = sns.lineplot(x = "Year", y = "Price per kilogram", data = df, hue = "Store type");
ax.xaxis.set_major_locator(mticker.MultipleLocator(3))
plt.show()
df2 = pd.read_csv("/Users/rahuldas/Desktop/Tortilla Dataset/wfp_food_prices_mex.csv", skiprows=[1])
print(df2.head)
print(df2.info())
df2["date"] = pd.to_datetime(df2["date"])
print(df2.info())
df2['Year'] = pd.DatetimeIndex(df2['date']).year
print(df2.columns)
print(df.head())
print(df2.head())
df_combined = pd.merge(df, df2, on="Year", how="outer")
print(df_combined.head())
print(df_combined.info())
``` @zealous galleon , is this along what you had in mind?
this literally crashes my mac
Pandas merge function provides functionality similar to database joins. You can merge two data frames using a column. One can perform left, right, outer or inner joins on these dataframes. This tutorial also covers indicator and suffixes flags in pandas.merge function.
Topics that are covered in this Python Pandas Video:
0:00 Introduction
0:42 ...
i'm looking at this vid
it still gives only 5 rows and 21 columns
!close
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.