George_Zagorsky_1

Untitled

Mar 9th, 2022
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 22.26 KB | None | 0 0
  1. import pandas
  2.  
  3.  
  4. def rename_columns(csv_file):  # fuction to rename bad columns
  5.     csv_file = csv_file.rename(
  6.         columns={'Price $': 'Price', 'FBA Fees $': 'FBA_Fees', 'Active Sellers #': 'Active_Sellers',
  7.                  'Product Details': 'Product_Details', 'Review Count': 'Review_Count',
  8.                  'Review velocity': 'Review_velocity', 'Buy Box': 'Buy_Box', 'Size Tier': 'Size_Tier',
  9.                  'Creation Date': 'Creation_Date'})
  10.  
  11.     return csv_file
  12.  
  13.  
  14. def drop_all_duplicates(csv_file):
  15.     csv_file = csv_file.drop_duplicates().reset_index(drop=True)
  16.     return csv_file
  17.  
  18.  
  19. def rename_words(csv):  # fuction to rename all NANS to 'UNKNOWN'
  20.     list = sum(csv.isna().sum())
  21.     if list != 0:
  22.         for element in csv.columns:
  23.             csv[element] = csv[element].fillna('UNKNOWN')
  24.     return csv
  25.  
  26.  
  27. def remove_all_commas(csv_file):  # fucnction to remove all commas from csv file
  28.     array = ['Price', 'Sales', 'Revenue', 'Review_Count', 'Review_velocity', 'BSR', 'FBA_Fees', 'Active_Sellers',
  29.              'Images', 'Weight']
  30.     data_frame = pandas.DataFrame(csv_file)
  31.     for element in array:
  32.         i = 0
  33.         for el in data_frame[element]:
  34.             answer = ''
  35.             stack = []
  36.             if type(el) == str:
  37.                 if el != 'UNKNOWN':
  38.                     if ',' in el:
  39.                         for new_el in el:
  40.                             if new_el.isdigit() or new_el == '.':
  41.                                 stack.append(new_el)
  42.                             else:
  43.                                 continue
  44.                         for key in stack:
  45.                             answer += key
  46.                         if element in ['Sales', 'Review_Count']:
  47.                             data_frame.loc[i, element] = int(answer)
  48.                             i += 1
  49.                         else:
  50.  
  51.                             data_frame.loc[i, element] = float(answer)
  52.                             i += 1
  53.                     else:
  54.                         if element in ['Sales', 'Review_Count']:
  55.                             result = int(el)
  56.                             data_frame.loc[i, element] = result
  57.                             i += 1
  58.                         else:
  59.                             result = float(el)
  60.                             data_frame.loc[i, element] = result
  61.                             i += 1
  62.  
  63.  
  64.  
  65.  
  66.             else:
  67.                 i += 1
  68.  
  69.     return data_frame
  70.  
  71.  
  72. def check_the_types(csv_file):  # have already yet
  73.     for element in csv_file.columns:
  74.         for el in csv_file[element]:
  75.             print(el, ' ', type(el))
  76.     return f'All types from all csv_file : {csv_file}'
  77.  
  78.  
  79. def remove_commas_test(csv_file):  # bad function for  future test
  80.     pass
  81.  
  82.  
  83. def convet_to_csv(data_frame):  # Fucton to convert data_frame as csv
  84.     csv_file = data_frame.to_csv('tested_file_for_amazon.csv')
  85.  
  86.     return csv_file
  87.  
  88.  
  89. def convert_revenue_to_int(csv_file):
  90.     index = 0
  91.     for element in list(csv_file['Revenue']):
  92.         if csv_file.loc[index, 'Revenue'] != 'UNKNOWN':
  93.             csv_file.loc[index, 'Revenue'] = int(csv_file.loc[index, 'Revenue'])
  94.         index += 1
  95.     return csv_file
  96.  
  97.  
  98. def remove_unknown_from_Revenue(csv_file):
  99.     index = 0
  100.     for element in list(csv_file['Revenue']):
  101.         if element == 'UNKNOWN':
  102.             csv_file.loc[index, 'Revenue'] = 0
  103.         index += 1
  104.  
  105.     return csv_file
  106.  
  107.  
  108. def sort_revenue(data_frame):  # test
  109.     data_frame = data_frame.sort_values('Revenue', ascending=False)
  110.     return data_frame
  111.  
  112.  
  113. def check_types_of_str_columns(csv_file):  # another fuction to check types
  114.     stack_of_columns = ['Price', 'Sales', 'Revenue', 'Review_Count', 'Review_velocity', 'BSR', 'FBA_Fees']
  115.     for name_of_column in stack_of_columns:
  116.         for element in csv_file[name_of_column]:
  117.             if type(element) == str:
  118.                 continue
  119.             else:
  120.                 print(f'The tipy of element is: {type(element)} and the element is : {element}')
  121.                 if type(element) == str:
  122.                     raise Exception
  123.  
  124.  
  125. def check_test(csv_file):  # fuction to understand types
  126.     for element in csv_file.columns:
  127.         for el in csv_file[element]:
  128.             print(el, ' ', type(el))
  129.     return False
  130.  
  131.  
  132. def find_sum_column_sales(csv_file):  # Find sum of sales column
  133.     result = 0
  134.     for element in list(csv_file['Sales']):
  135.         if element != 'UNKNOWN':
  136.             result += int(element)
  137.     return result
  138.  
  139.  
  140. def find_sum_of_revenue_column(csv_file):  # Find sum of Revenue
  141.     result = 0
  142.     for element in list(csv_file['Revenue']):
  143.         if element != 'UNKNOWN':
  144.             result += int(element)
  145.     return result
  146.  
  147.  
  148. def find_sum_of_price(csv_file):  # Find sum of Price column
  149.     result = 0
  150.     for element in list(csv_file['Price']):
  151.         if element != 'UNKNOWN':
  152.             result += int(element)
  153.  
  154.     return result
  155.  
  156.  
  157. def find_sum_of_review_count(csv_file):  # Find sum of Review_Count column
  158.     result = 0
  159.     for element in list(csv_file['Review_Count']):
  160.         result += int(element)
  161.  
  162.     return result
  163.  
  164.  
  165. def convert_unkown_to_digit_if_needed(csv_file):  # Function for future math - to rename all String to zero
  166.     stack_of_columns = ['Price', 'Sales', 'Revenue', 'Review_Count', 'Ratings', 'Review_velocity', 'BSR', 'FBA_Fees',
  167.                         'Active_Sellers']
  168.     for name in stack_of_columns:
  169.         i = 0
  170.         for element in csv_file[name]:
  171.             if type(element) == str:
  172.                 csv_file[name][i] = 0
  173.             i += 1
  174.  
  175.     return csv_file
  176.  
  177.  
  178. def work_with_columns(csv_file):  # Find sum of Revenue Column - second - for the most reason
  179.     counter = 0
  180.     for element in csv_file['Revenue']:
  181.         counter += element
  182.  
  183.     return counter
  184.  
  185.  
  186. def create_sample():  # create sample for future csv
  187.     rows_for_csv = [
  188.         ['Face_Mask', 0, 0, 0, 0, 0, 0, 0, 0, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
  189.         [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'GR1', 'GR2',
  190.          'GR3', 'REST', '0-99', '100-499', '500-999', '1000'],
  191.         [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '(1-3) G1R', '(4-9) G2R', '(10-16) G3R', '(16-58) G4R',
  192.          '(1-3) G1AR', '(4-9) G2AR', '(10-16) G3AR', '(16-58) G4AR', 0, 0, 0, 0, 0, 0, 0, 0],
  193.         [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 0, 0, 0, 0, 0, 0, 0, 0, ' ', ' ', ' ', ' ', ' ', ' ', ' ',
  194.          ' '],
  195.         [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '(1-3) G1RW', '(4-9) G2RW', '(10-16) G3RW',
  196.          '(16-58) G4RW', '(1-3) G1ARW', '(4-9) G2ARW', '(10-16) G3ARW', '(16-58) G4ARW', ' ', ' ', ' ', ' ', 0,
  197.          0, 0, 0],
  198.         [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 0, 0, 0, 0, 0, 0, 0, 0, ' ', ' ', ' ', ' ', ' ', ' ', ' ',
  199.          ' ']
  200.     ]
  201.     columns_for_csv = ['Product', 'Main_Search_Terms', 'Revenue', 'Avg. Reviews', 'Review per Revenue (RPR)',
  202.                        'Sales (GR1, GR2, GR3)', 'Review Velocity (GR1, GR2, GR3)', 'Review CVR (GR1, GR2, GR3)',
  203.                        'Products per Page', 'GxR / GxRW', '1', '2', '3', 'GxAR / GxARW', '4', '5',
  204.                        '6',
  205.                        'Groups Share', '7', '8', '9',
  206.                        '\tAvg. Revenue for Groups by Reviews and Listings Count',
  207.                        '10', '11', '12']
  208.  
  209.     data_frame = pandas.DataFrame(data=rows_for_csv, columns=columns_for_csv)
  210.     return data_frame
  211.  
  212.  
  213. def check_types(csv_file):  # have allready done
  214.     for element in csv_file.columns:
  215.         for el in csv_file[element]:
  216.             print(el, ' : ', type(el))
  217.     pass
  218.  
  219.  
  220. def find_revenue_sum(data_frame_sample, csv_file_as_data_frame):
  221.     stack = [element for element in list(csv_file_as_data_frame['Revenue']) if element != 'UNKNOWN']
  222.     result_sum = sum(stack)
  223.     data_frame_sample.loc[0, 'Revenue'] = int(result_sum)
  224.     return data_frame_sample
  225.  
  226.  
  227. def find_sum_of_revenue_columns(csv_file, sample_of_data_frame):
  228.     summa = int(sum([x for x in list(csv_file['Revenue']) if x != 'UNKNOWN']))
  229.  
  230.     sample_of_data_frame.loc[0, 'Revenue'] = summa
  231.     pass
  232.  
  233.  
  234. def find_mean_avg_reviews(csv_file, sample_of_data_frame):  # ?
  235.     summa = int(sum([x for x in list(csv_file['Review_Count']) if x != 'UNKNOWN']))
  236.     length = len([x for x in list(csv_file['Review_Count']) if x != 'UNKNOWN'])
  237.     mean = summa / length
  238.     sample_of_data_frame.loc[0, 'Avg. Reviews'] = int(mean)
  239.     return sample_of_data_frame
  240.  
  241.  
  242. def review_per_revenue(sample_data_frame):
  243.     sample_data_frame.loc[0, 'Review per Revenue (RPR)'] = int(
  244.         sample_data_frame.loc[0, 'Revenue'] / sample_data_frame.loc[
  245.             0, 'Avg. Reviews'])
  246.     return sample_data_frame
  247.  
  248.  
  249. def find_sum_of_sales(csv_file, sample_of_data_frame):  # proverit' na real case
  250.     stack = csv_file['Sales'][0:16]
  251.     filtered_array = [x for x in stack if x != 'UNKNOWN']
  252.     sample_of_data_frame.loc[0, 'Sales (GR1, GR2, GR3)'] = sum(filtered_array)
  253.     return sample_of_data_frame
  254.  
  255.  
  256. def find_sum_review_velocity(sample_data_frame, csv_file):
  257.     array_of_velocity = csv_file['Review_velocity'][0:16]
  258.     array_of_velocity = [x for x in array_of_velocity if x != 'UNKNOWN']
  259.     sample_data_frame.loc[0, 'Review Velocity (GR1, GR2, GR3)'] = sum(array_of_velocity)
  260.     return sample_data_frame
  261.  
  262.  
  263. def find_percent_velocity_sales(sample_data_frame):
  264.     result = (sample_data_frame.loc[0, 'Review Velocity (GR1, GR2, GR3)'] / sample_data_frame.loc[
  265.         0, 'Sales (GR1, GR2, GR3)']) * 100
  266.     result = str(result)
  267.     stack = []
  268.     counter = 0
  269.     for element in result:
  270.         stack.append(element)
  271.         counter += 1
  272.         if counter == 4:
  273.             break
  274.     answer = ''
  275.     for element in stack:
  276.         answer += element
  277.     sample_data_frame.loc[0, 'Review CVR (GR1, GR2, GR3)'] = answer + '%'
  278.     return sample_data_frame
  279.  
  280.  
  281. def product_pet_page(csv_file, sample_data_frame):
  282.     lenght = len(csv_file)
  283.     sample_data_frame.loc[0, 'Products per Page'] = lenght
  284.     return sample_data_frame
  285.  
  286.  
  287. def find_avg_review(csv_file, data_frame):
  288.     stack_of_revenue = csv_file['Revenue'][0:3]
  289.     filtered_array = [x for x in stack_of_revenue if x != 'UNKNOWN']
  290.     result_sum = sum(filtered_array)
  291.     length = len(filtered_array)
  292.     data_frame.loc[3, 'GxAR / GxARW'] = str(int(result_sum / length)) + '$'
  293.     return data_frame
  294.  
  295.  
  296. def find_sum_group_1_3(csv_file, sample_data_frame):
  297.     stack_of_revenue = csv_file['Revenue'][0:3]
  298.     filtered_array = [x for x in stack_of_revenue if x != 'UNKNOWN']
  299.     result_sum = sum(filtered_array)
  300.     sample_data_frame.loc[3, 'GxR / GxRW'] = str(int(result_sum)) + '$'
  301.     return sample_data_frame
  302.  
  303.  
  304. def csv_file_to_data_frame_and_back(csv_file):
  305.     data_frame = pandas.DataFrame(csv_file)
  306.     realod_csv = data_frame.to_csv('for_boys_answers.csv')
  307.     return realod_csv
  308.  
  309.  
  310. def find_avg_second_review(csv_file, data_frame):
  311.     stack_of_group = csv_file['Revenue'][3:9]
  312.     filtered_array = [x for x in stack_of_group if x != 'UNKNOWN']
  313.     result_sum = sum(filtered_array)
  314.     length = len(filtered_array)
  315.     data_frame.loc[3, '4'] = str(int(result_sum / length)) + '$'
  316.     return data_frame
  317.  
  318.  
  319. def find_sum_group_4_9(csv_file, sample_data_frame):
  320.     stack_of_group = csv_file['Revenue'][3:9]
  321.     filtered_array = [x for x in stack_of_group if x != 'UNKNOWN']
  322.     result_sum = sum(filtered_array)
  323.     sample_data_frame.loc[3, '1'] = str(int(result_sum)) + '$'
  324.     return sample_data_frame
  325.  
  326.  
  327. def find_third_revenue_avg(csv_file, data_frame):
  328.     stack_group = csv_file['Revenue'][9:16]
  329.     filtered_array = [x for x in stack_group if x != 'UNKNOWN']
  330.     result_sum = sum(filtered_array)
  331.     length = len(filtered_array)
  332.     data_frame.loc[3, '5'] = str(int(result_sum / length)) + '$'
  333.     return data_frame
  334.  
  335.  
  336. def find_sum_revenue_10_16(csv_file, sample_data_frame):
  337.     stack_group = csv_file['Revenue'][9:16]
  338.     filtered_array = [x for x in stack_group if x != 'UNKNOWN']
  339.     result_sum = sum(filtered_array)
  340.     sample_data_frame.loc[3, '2'] = str(int(result_sum)) + '$'
  341.     return sample_data_frame
  342.  
  343.  
  344. def find_fourth_avg_reviews(csv_file, data_frame):
  345.     stack_group = csv_file['Revenue'][16:len(csv_file)]
  346.     filtered_array = [x for x in stack_group if x != 'UNKNOWN']
  347.     result_sum = sum(filtered_array)
  348.     length = len(filtered_array)
  349.     data_frame.loc[3, '6'] = str(int(result_sum / length)) + '$'
  350.     return data_frame
  351.  
  352.  
  353. def find_sum_17_to_last(csv_file, sample_data_frame):
  354.     stack_group = csv_file['Revenue'][16:len(csv_file)]
  355.     filtered_array = [x for x in stack_group if x != 'UNKNOWN']
  356.     result_sum = sum(filtered_array)
  357.     sample_data_frame.loc[3, '3'] = str(int(result_sum)) + '$'
  358.     return sample_data_frame
  359.  
  360.  
  361. def find_avg_review_count_1(csv_file, data_frame):
  362.     stack_review_count = csv_file['Review_Count'][0:3]
  363.     filtered_stack = [x for x in stack_review_count if x != 'UNKNOWN']
  364.     result_sum = sum(filtered_stack)
  365.     length = len(filtered_stack)
  366.     data_frame.loc[5, 'GxAR / GxARW'] = str(int(result_sum / length))
  367.     return data_frame
  368.  
  369.  
  370. def find_sum_review_count_1_3(csv_file, sample_data_frame):
  371.     stack_review_count = csv_file['Review_Count'][0:3]
  372.     filtered_stack = [x for x in stack_review_count if x != 'UNKNOWN']
  373.     result_sum = sum(filtered_stack)
  374.     sample_data_frame.loc[5, 'GxR / GxRW'] = int(result_sum)
  375.     return sample_data_frame
  376.  
  377.  
  378. def find_avg_review_count_2(csv_file, data_frame):
  379.     stack = csv_file['Review_Count'][3:9]
  380.     filtered_stack = [x for x in stack if x != 'UNKNOWN']
  381.     sum_result = sum(filtered_stack)
  382.     length = len(filtered_stack)
  383.     data_frame.loc[5, '4'] = str(int(sum_result / length))
  384.     return data_frame
  385.  
  386.  
  387. def find_sum_review_count_4_9(csv_file, sample_data_frame):
  388.     stack = csv_file['Review_Count'][3:9]
  389.     filtered_stack = [x for x in stack if x != 'UNKNOWN']
  390.     sum_result = sum(filtered_stack)
  391.     sample_data_frame.loc[5, '1'] = int(sum_result)
  392.     return sample_data_frame
  393.  
  394.  
  395. def find_avg_review_count_3(csv_file, data_frame):
  396.     filtered_stack = [x for x in list(csv_file['Review_Count'][9:16]) if x != 'UNKNOWN']
  397.     sum_result = sum(filtered_stack)
  398.     length = len(filtered_stack)
  399.     data_frame.loc[5, '5'] = str(int(sum_result / length))
  400.     return data_frame
  401.  
  402.  
  403. def find_sum_review_count_10_16(csv_file, sample_data_frame):
  404.     filtered_stack = [x for x in list(csv_file['Review_Count'][9:16]) if x != 'UNKNOWN']
  405.     sum_result = sum(filtered_stack)
  406.     sample_data_frame.loc[5, '2'] = int(sum_result)
  407.     return sample_data_frame
  408.  
  409.  
  410. def find_avg_review_count_4(csv_file, data_frame):
  411.     stack_review_count = csv_file['Review_Count'][16:len(csv_file)]
  412.     filtered_array = [x for x in stack_review_count if x != 'UNKNOWN']
  413.     result_sum = sum(filtered_array)
  414.     length = len(filtered_array)
  415.     data_frame.loc[5, '6'] = str(int(result_sum / length))
  416.     return data_frame
  417.  
  418.  
  419. def find_sum_review_count_16_last(csv_file, sample_data_frame):
  420.     stack_review_count = csv_file['Review_Count'][16:len(csv_file)]
  421.     filtered_array = [x for x in stack_review_count if x != 'UNKNOWN']
  422.     result_sum = sum(filtered_array)
  423.     sample_data_frame.loc[5, '3'] = int(result_sum)
  424.     return sample_data_frame
  425.  
  426. def remove_dollar_from_revenue_groups(data_frame):
  427.     stack_of_replacement = ['GxR / GxRW', '1', '2', '3']
  428.     for element in stack_of_replacement:
  429.         data_frame.loc[3, element] = data_frame.loc[3, element].replace('$', '')
  430.     return data_frame
  431.  
  432.  
  433. def replace_type_revenue_groups(data_frame):
  434.     stack_of_replacement = ['GxR / GxRW', '1', '2', '3']
  435.     for element in stack_of_replacement:
  436.         data_frame.loc[3, element] = int(data_frame.loc[3, element])
  437.  
  438.     return data_frame
  439.  
  440.  
  441. def all_types_review_count_to_int(csv_file):
  442.     stack = ['Review_Count']
  443.     counter = 0
  444.     for element in stack:
  445.         for el in csv_file[element]:
  446.             csv_file.loc[counter, element] = int(csv_file.loc[counter, element])
  447.  
  448.     return csv_file
  449.  
  450.  
  451. def sort_for_review_count(csv_file):
  452.     csv_file = csv_file.sort_values('Review_Count', ascending = False)
  453.     return csv_file
  454.  
  455. def find_sum_from_zero_to_hundred(csv_file, data_frame):
  456.     new_csv = csv_file[csv_file['Review_Count'] < 100]
  457.     filtered_array = [x for x in list(new_csv['Revenue']) if x != 'UNKNOWN']
  458.     result_sum = sum(filtered_array)
  459.     data_frame.loc[2, 'Avg. Revenue for Groups by Reviews and Listings Count'] = int(result_sum)
  460.     return data_frame
  461.  
  462.  
  463. def find_sum_from_hundred_to_5_hundred(csv_file, data_frame):
  464.     new_csv = csv_file[csv_file['Review_Count'] > 100]
  465.     new_csv = new_csv[new_csv['Review_Count'] < 500]
  466.     filtered_array = [x for x in list(new_csv['Revenue']) if x != 'UNKNOWN']
  467.     result_sum = sum(filtered_array)
  468.     data_frame.loc[2, '10'] = int(result_sum)
  469.     return data_frame
  470.  
  471. def find_sum_from_5_hundred_to_1_thousand(csv_file, data_frame):
  472.     new_csv = csv_file[csv_file['Review_Count'] < 1000]
  473.     new_csv = new_csv[new_csv['Review_Count'] > 500]
  474.     filtered_array = [x for x in list(new_csv['Revenue']) if x != 'UNKNOWN']
  475.     result_sum = sum(filtered_array)
  476.     data_frame.loc[2, '11'] = int(result_sum)
  477.     return data_frame
  478.  
  479. def find_sum_more_than_thousand(csv_filem, data_frame):
  480.     new_csv = csv_filem[csv_filem['Review_Count'] > 1000]
  481.     filtered_array = [x for x in list(new_csv['Revenue']) if x != 'UNKNOWN']
  482.     result_sum = sum(filtered_array)
  483.     data_frame.loc[2, '12'] = int(result_sum)
  484.     return data_frame
  485.  
  486. def groups_share_1(data_frame):
  487.     #formula : GxR / sum(revenue) * 100
  488.     first_group = data_frame.loc[3, 'GxR / GxRW']
  489.     result_sum = data_frame.loc[0, 'Revenue']
  490.     data_frame.loc[2, 'Groups Share'] = str(int((first_group / result_sum) * 100)) + '%'
  491.     return data_frame
  492.  
  493. def groups_share_2(data_frame):
  494.     second_group = data_frame.loc[3, '1']
  495.     result_sum = data_frame.loc[0, 'Revenue']
  496.     data_frame.loc[2, '7'] = str(int((second_group / result_sum) * 100)) + '%'
  497.     return data_frame
  498.  
  499.  
  500. def groups_share_3(data_frame):
  501.     third_group = data_frame.loc[3, '2']
  502.     result_sum = data_frame.loc[0, 'Revenue']
  503.     data_frame.loc[2, '8'] = str(int((third_group / result_sum) * 100 )) + '%'
  504.     return data_frame
  505.  
  506. def groups_share_delta(data_frame):
  507.     delta_group = data_frame.loc[3, '6']
  508.     result_sum = data_frame.loc[0, 'Revenue']
  509.     data_frame.loc[2, '9'] = str(int((delta_group / result_sum) * 100)) + '%'
  510.     return data_frame
  511.  
  512.  
  513.  
  514.  
  515. def length_reviews_0_99(csv_file, data_frame):
  516.     new_csv = csv_file[csv_file['Review_Count'] < 100]
  517.     length = len(new_csv)
  518.     data_frame.loc[4, '\tAvg. Revenue for Groups by Reviews and Listings Count'] = length
  519.     return data_frame
  520.  
  521. def lenth_reviews_100_500(csv_file, data_frame):
  522.     new_csv = csv_file[csv_file['Review_Count'] > 100]
  523.     new_csv = new_csv[new_csv['Review_Count'] < 500]
  524.     length = len(new_csv)
  525.     data_frame.loc[4, '10'] = length
  526.     return data_frame
  527.  
  528.  
  529. def length_reviews_500_1000(csv_file, data_frame):
  530.     new_csv = csv_file[csv_file['Review_Count'] > 500]
  531.     new_csv = new_csv[new_csv['Review_Count'] < 1000]
  532.     data_frame.loc[4, '11'] = len(new_csv)
  533.     return data_frame
  534.  
  535.  
  536. def length_reviews_more_then_thousand(csv_file, data_frame):
  537.     new_csv = csv_file[csv_file['Review_Count'] > 1000]
  538.     length = len(new_csv)
  539.     data_frame.loc[4, '12'] = length
  540.     return data_frame
  541.  
  542.  
  543. def swap_int_to_str_groups(data_frame):
  544.     stack_of_groups = ['GxR / GxRW', '1', '2', '3']
  545.     for element in stack_of_groups:
  546.         data_frame.loc[3, element] = str(data_frame.loc[3, element]) + '%'
  547.     return data_frame
  548.  
  549.  
  550. def remove_all_digits_from_columns(data_frame):
  551.     data_frame = data_frame.rename(columns = {'1' : ' ', '2' : ' ', '3' : ' ', '4' : ' ', '5' : ' ', '6' : ' ', '7' : ' ', '8' : ' ', '9' : ' ', '10' : ' ', '11' : ' ', '12' : ' '})
  552.     return data_frame
  553.  
  554.  
  555. def swap_int_to_str(data_frame):
  556.     data_frame.loc[0, 'Revenue'] = str(data_frame.loc[0, 'Revenue']) + '$'
  557.     return data_frame
  558.  
  559.  
  560.  
  561.  
  562.  
  563.  
  564.  
  565. if __name__ == '__main__':
  566.     file_for_amazon_csv = pandas.read_csv('"D:\naruto\Helium_10_Xray_2022-02-12.csv"')
  567.     file_for_amazon_csv = pandas.DataFrame(file_for_amazon_csv)  # test
  568.     file_for_amazon_csv = rename_columns(file_for_amazon_csv)
  569.     file_for_amazon_csv = drop_all_duplicates(file_for_amazon_csv)
  570.     file_for_amazon_csv = rename_words(file_for_amazon_csv)
  571.     file_for_amazon_csv = remove_all_commas(file_for_amazon_csv)
  572.     file_for_amazon_csv = convert_revenue_to_int(file_for_amazon_csv)
  573.     file_for_amazon_csv = remove_unknown_from_Revenue(file_for_amazon_csv)
  574.     file_for_amazon_csv = sort_revenue(file_for_amazon_csv)
  575.     data_frame = create_sample()
  576.     data_frame = find_revenue_sum(data_frame, file_for_amazon_csv)
  577.     data_frame = find_mean_avg_reviews(file_for_amazon_csv, data_frame)
  578.     data_frame = review_per_revenue(data_frame)
  579.     data_frame = find_sum_of_sales(file_for_amazon_csv, data_frame)
  580.     data_frame = find_sum_review_velocity(data_frame, file_for_amazon_csv)
  581.     data_frame = find_percent_velocity_sales(data_frame)
  582.     data_frame = product_pet_page(file_for_amazon_csv, data_frame)
  583.     data_frame = find_sum_group_1_3(file_for_amazon_csv, data_frame)
  584.     data_frame = find_sum_group_4_9(file_for_amazon_csv, data_frame)
  585.     data_frame = find_sum_revenue_10_16(file_for_amazon_csv, data_frame)
  586.     data_frame = find_sum_17_to_last(file_for_amazon_csv, data_frame)
  587.     data_frame = find_sum_review_count_1_3(file_for_amazon_csv, data_frame)
  588.     data_frame = find_sum_review_count_4_9(file_for_amazon_csv, data_frame)
  589.     data_frame = find_sum_review_count_10_16(file_for_amazon_csv, data_frame)
  590.     data_frame = find_sum_review_count_16_last(file_for_amazon_csv, data_frame)
  591.     data_frame = find_avg_review(file_for_amazon_csv, data_frame)
  592.     data_frame = find_avg_second_review(file_for_amazon_csv, data_frame)
  593.     data_frame = find_third_revenue_avg(file_for_amazon_csv, data_frame)
  594.     data_frame = find_fourth_avg_reviews(file_for_amazon_csv, data_frame)
  595.     data_frame = find_avg_review_count_1(file_for_amazon_csv, data_frame)
  596.     data_frame = find_avg_review_count_2(file_for_amazon_csv, data_frame)
  597.     data_frame = find_avg_review_count_3(file_for_amazon_csv, data_frame)
  598.     data_frame = find_avg_review_count_4(file_for_amazon_csv, data_frame)
  599.     file_for_amazon_csv = convet_to_csv(data_frame)
  600.  
Advertisement
Add Comment
Please, Sign In to add comment